I am fairly new to programming and I need some help with a simple strategy.
The basics are: I want to place a trade in the begining of every hour, based on the close of the previous bar. Really simple: if Red --> Short, if Green --> Long. Same size for all the trades and same amount of pips for stoploss and take profit.
I only want to trade between 7 and 4pm, therefore 10 trades in total per day.
So far so good, my problem comes when I have to put my stop and target pending orders in. Since I cannot use Managed Orders, (due to the fact that buy and sell positions come during the day, and I do not want to cancel all current positions when the direction is reversed).
Can someone help me how to sort out the stop loss and target pending orders for these trades? I will copy a part of the code, I know I am missing a lot of stuff.
if (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) <= 160000) if (Close[1] <= Close[0]) if (Historical == false) { SubmitOrder (0, OrderAction.Buy, OrderType.Market, DefaultQuantity, 0, 0,"","Longpos"); SubmitOrder (0, OrderAction.Sell, OrderType.Limit, DefaultQuantity, GetCurrentAsk() + (Target * TickSize), 0, "longpending", "LongTarget"); SubmitOrder (0, OrderAction.Sell, OrderType.Stop, DefaultQuantity, GetCurrentAsk() - (StopLoss * TickSize), 0, "longpending", "LongStop"); } // Condition set 2 if (ToTime(Time[0]) >= 70000 && ToTime(Time[0]) <= 160000) if (Close[1] > Close[0]) if (Historical == false) { SubmitOrder (0, OrderAction.Sell, OrderType.Market, DefaultQuantity, GetCurrentBid() - (Target * TickSize), GetCurrentBid() + (StopLoss * TickSize),"","Shortpos"); SubmitOrder (0, OrderAction.Buy, OrderType.Limit,DefaultQuantity, GetCurrentAsk() - (Target * TickSize), 0, "shortpending", "ShortTarget"); SubmitOrder (0, OrderAction.Buy, OrderType.Stop, DefaultQuantity, GetCurrentAsk() + (StopLoss * TickSize), 0, "shortpending", "ShortStop");
Thanks.
Comment