I need help with setting the logic properly for order opening…. What is the best practice to open an order if the price hits a line? (also, with Slippage)
=============================
Variables for Order Opening:
Logic needing review and advice:
=============================
Variables for Order Opening:
Inserted Code
int i; // Bar index int Counted_bars; // Number of counted bars Counted_bars=IndicatorCounted(); // Number of counted bars i=Bars-Counted_bars-1; // Index of the first uncounted while(i>=0) // Loop for uncounted bars { double MA_Line=iCustom(NULL,timeframe,"MA+StdDev",MA_Period, 1, 6, 0, 0,i); double S_Line1=iCustom(NULL,timeframe,"MA+StdDev",MA_Period, 1, 6, 0, 1,i); double S_Line2=iCustom(NULL,timeframe,"MA+StdDev",MA_Period, 1, 6, 0, 2,i); double S_Line3=iCustom(NULL,timeframe,"MA+StdDev",MA_Period, 1, 6, 0, 3,i); double S_Line4=iCustom(NULL,timeframe,"MA+StdDev",MA_Period, 1, 6, 0, 4,i); double U_StopLoss=iCustom(NULL,timeframe,"MA+StdDev",MA_Period, 1, 6, 0, 5,i); double L_StopLoss=iCustom(NULL,timeframe,"MA-StdDev",MA_Period, 1, 6, 0, 5,i); double B_Line1=iCustom(NULL,timeframe,"MA-StdDev",MA_Period, 1, 6, 0, 1,i); double B_Line2=iCustom(NULL,timeframe,"MA-StdDev",MA_Period, 1, 6, 0, 2,i); double B_Line3=iCustom(NULL,timeframe,"MA-StdDev",MA_Period, 1, 6, 0, 3,i); double B_Line4=iCustom(NULL,timeframe,"MA-StdDev",MA_Period, 1, 6, 0, 4,i); double StochBuyLine = iStochastic(Symbol(),0,14,3,3,1,1,0,i); double StochSellLine = iStochastic(Symbol(),0,14,3,3,1,1,1,i); i--; }
Logic needing review and advice:
Inserted Code
if (Tradeable) else break; if CurrentPrice < MA_Line { if StochBuyLine>StochSellLine && StochBuyLine<=10 && CurrentPrice = B_Line4 {OpenBuyOrder @ Line4LotSize} Else if StochBuyLine>StochSellLine && StochBuyLine<=10 && CurrentPrice = B_Line3 {OpenBuyOrder @ Line3LotSize} Else if StochBuyLine>StochSellLine && StochBuyLine<=10 && CurrentPrice = B_Line2 {OpenBuyOrder @ Line2LotSize} Else if StochBuyLine>StochSellLine && StochBuyLine<=10 && CurrentPrice = B_Line1 {OpenBuyOrder @ Line1LotSize} } Else { if StochSellLine>StochBuyLine && StochSellLine>=90 && CurrentPrice = B_Line4 {OpenBuyOrder @ Line4LotSize} Else if StochSellLine && StochSellLine>=90 && CurrentPrice = B_Line3 {OpenBuyOrder @ Line3LotSize} Else if StochSellLine>StochBuyLine && StochSellLine>=90 && CurrentPrice = B_Line2 {OpenBuyOrder @ Line2LotSize} Else if StochSellLine>StochBuyLine && StochSellLine>=90 && CurrentPrice = B_Line1 {OpenBuyOrder @ Line1LotSize} [font="]}[/font]