Download MetaTrader 5
To add comments, please log in or register
Register at MQL5.community and leave your comments!
Akif Mushtaq
130
Akif Mushtaq 2015.10.26 05:34 

Im using the following code to trigger a buy order. What Im doing is looking for an outside candle, where the low of the current candle dips below the low of the previous candle....and then the high of the current candle breaches the high of previous  candle. The following logic only works if its an outside candle. (i-e, current low is less than prev low, and current high is higher than prev high)  

[code]bool buy_condition_1 = Low[0] <= Low[1];

bool buy_condition_2 = Ask == High[1] ; 

 if( buy_condition_1 && buy_condition_2).................(buy at current ask) 

[/code]

What i want to do is that if the current low is less than prev low, then set the buy price at the high[1]...and hold that buy price until it is hit. In the above code, the  price is hit only if its an outside candle, and as soon as a new candle is formed, the value of High[1] shifts to the new candle as well. I want value of High[1] to remain fixed. 

Adam Slucki
411
Adam Slucki 2015.10.26 11:01  
What i want to do is that if the current low is less than prev low, then set the buy price at the high[1]...and hold that buy price until it is hit. In the above code, the  price is hit only if its an outside candle, and as soon as a new candle is formed, the value of High[1] shifts to the new candle as well. I want value of High[1] to remain fixed. 
The easiest thing you can do is placing a pending order with High[1] as one of the parameters.
It means you can delete your buy_condition_2 variable and instead have something like:
 
bool buy_condition_1 = Low[0] <= Low[1];
if( buy_condition_1 )OrderSend(Symbol(), OP_BUYSTOP,1,High[1],50,50);
Of course you should also check if OrderSend returned true, pass correct possition volume etc.
Hope it helps.
Akif Mushtaq
130
Akif Mushtaq 2015.10.26 12:56  
Adam Slucki:
The easiest thing you can do is placing a pending order with High[1] as one of the parameters.
It means you can delete your buy_condition_2 variable and instead have something like:
 Of course you should also check if OrderSend returned true, pass correct possition volume etc.
Hope it helps.

Thanks Adam...but that didnt seem to help.

I guess i can set the value by declaring it as a static double, but my next question would be, how would i reset its value, should i need to change it? Is there a way to reset the value of a static variable mid strategy, so as to assign in a new value?.

Marco vd Heijden
Moderator
4506
Marco vd Heijden 2015.10.26 14:05  
copy the static to a dynamic variable then you can change that.
/
To add comments, please log in or register