martingale - checking if position closed at a loss

 

Hi everyone,

I know my question might be a bit stupid to those of you more experienced but I really need help with an issue I have run into.
I am reasonably new to coding, and I have been spending the past 4 hours looking through the forums and google for how to do this and I can't find an answer I can understand or that works for me.
I am trying to make a basic EA using the martingale where I check if the trade closed on the stop loss and if it did then to double the trade volume of the next trade, and if it closed on the take profit to reset the trade volume to 

the original lower setting. 

double TradeVolume = 0.01;     

if(PRICE_OPEN > PRICE_CLOSE){
          TradeVolume = TradeVolume * 2;
          }else if(PRICE_OPEN < PRICE_CLOSE){
          TradeVolume = 0.01;

}

I have added this for buy orders and switched the > and < around for the sell order. 
I'm not sure if PRICE_OPEN and PRICE_CLOSE are the right things to be comparing to find out if the trade was at a loss or profit.
Also, when I run this code in the EA, it only places one trade then stops.

Any help would be greatly appreciated. Sorry for coming across as a total newbie.

 

you have to choose which order's open and close price first

after that you may work with order open price and close price

 
Ahmet Metin Yilmaz:

you have to choose which order's open and close price first

after that you may work with order open price and close price

Thanks for your fast reply,
Would I use orderselect() or select() for that? 
 

in your case,

OrderHistoryTotal() and  OrderSelect()

https://docs.mql4.com/trading/ordershistorytotal

OrdersHistoryTotal - Trade Functions - MQL4 Reference
OrdersHistoryTotal - Trade Functions - MQL4 Reference
  • docs.mql4.com
The number of closed orders in the account history loaded into the terminal. The history list size depends on the current settings of the "Account history" tab of the terminal.
 
Ahmet Metin Yilmaz:

in your case,

OrderHistoryTotal() and  OrderSelect()

https://docs.mql4.com/trading/ordershistorytotal

Thanks so much. I'll give it a try now and update here if I get it working
 
EANOOB:
Thanks so much. I'll give it a try now and update here if I get it working

youre welcome :)

 
check the order profit and order volume to work with