martingale - checking if position closed at a loss

To add comments, please log in or register
EANOOB
19
EANOOB  

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.

Ahmet Metin Yilmaz
4075
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

EANOOB
19
EANOOB  
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? 
Ahmet Metin Yilmaz
4075
Ahmet Metin Yilmaz  

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.
EANOOB
19
EANOOB  
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
Ahmet Metin Yilmaz
4075
Ahmet Metin Yilmaz  
EANOOB:
Thanks so much. I'll give it a try now and update here if I get it working

youre welcome :)

Dua Yong Rew
5669
Dua Yong Rew  
check the order profit and order volume to work with
To add comments, please log in or register