Hi, would you please help me with the code for increasing lot if market order closed with a loss and lot to stay the same if market order closed with profit.
for an example if EA start with (0.1 lot ) to trade, lot must increase to 0.2 if market order closed with a loss and to 0.3 lot if market order still closed in a loss. But lot must stay as 0.1 lot as long as market order closed with profit.
I will be glad if I can get a tip on how to solve such a problem.
Thanks
Hi, would you please help me with the code for increasing lot if market order closed with a loss and lot to stay the same if market order closed with profit.
for an example if EA start with (0.1 lot ) to trade, lot must increase to 0.2 if market order closed with a loss and to 0.3 lot if market order still closed in a loss. But lot must stay as 0.1 lot as long as market order closed with profit.
I will be glad if I can get a tip on how to solve such a problem.
Thanks
Hi Velly,
a comment which probably doesn't belong in this forum (as it does not deal with MQL): Martingale is [i]not[/i] an advisable strategy. :)
You might want to reconsider.
Cheers,
P.
- Martingale strategy will kill your account eventually
- Martingale strategy goes back to the starting lot size on a win, not stay the the last size
- Since there are no slaves here, there are only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
Loop through the Order History to find the last closed order that matches your Symbol and Magic Number (if used), then if OrderProfit() is negative change your position size for the next order . . . what is the problem ?
Thank you very much RaptorUK that was helpful.
- Martingale strategy will kill your account eventually
- Martingale strategy goes back to the starting lot size on a win, not stay the the last size
- Since there are no slaves here, there are only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
I get it WHRoeder, I'm still learning. Anyway thanks for the advice.
Hi Velly,
a comment which probably doesn't belong in this forum (as it does not deal with MQL): Martingale is [i]not[/i] an advisable strategy. :)
You might want to reconsider.
Cheers,
P.
Thank you.
Hi, would you please help me with the code for increasing lot if market order closed with a loss and lot to stay the same if market order closed with profit.
for an example if EA start with (0.1 lot ) to trade, lot must increase to 0.2 if market order closed with a loss and to 0.3 lot if market order still closed in a loss. But lot must stay as 0.1 lot as long as market order closed with profit.
I will be glad if I can get a tip on how to solve such a problem.
Thanks
try this code.
//----------------------- Externals ---------------------------------------------------------------- extern string Money_Management = "==== Money Management ===="; extern bool MoneyManagement = true; // Auto lot size extern double RiskFactor = 10; // Risk for money management (from 0.1 to 50) extern double ManualLotSize = 0.01; // Manual lot size extern bool RecoveryLot = false; // Recovery lot if loss order extern double MultiplierLot = 2; // Multiplier lot recovery extern int MagicNumber = 777; // Identifier //===================================================================================================================// int start() { double LotSize=CalcLots(); //--------- //your code...... //--------- return(0); } //===================================================================================================================// //lot size double CalcLots() { double MinLot=NormalizeDouble(MarketInfo(Symbol(),MODE_MINLOT),2); double MaxLot=NormalizeDouble(MarketInfo(Symbol(),MODE_MAXLOT),2); double LotStep=NormalizeDouble(MarketInfo(Symbol(),MODE_LOTSTEP),2); double LotValue=MarketInfo(Symbol(),MODE_LOTSIZE); double LotSize,Lot; int LotDigit; double Multiplier=1; double LastLot=0; //------------------------------------------------------ //Limit risk level RiskFactor=MathMin(MathMax(RiskFactor,0.1),50);//Risk between 0.1 - 50 //------------------------------------------------------ //Auto lot size if(MoneyManagement==true) LotSize=(AccountFreeMargin()/LotValue)*RiskFactor; //------------------------------------------------------ //Manual lot size if(MoneyManagement==false) LotSize=ManualLotSize; //------------------------------------------------------ //Lot digit if(LotStep==1)LotDigit=0; if(LotStep==0.1)LotDigit=1; if(LotStep==0.01)LotDigit=2; //------------------------------------------------------ //Check last order for loss or profit if(RecoveryLot==true) { for(int iCnt=0; iCnt<OrdersHistoryTotal(); iCnt++) { if(OrderSelect(iCnt,SELECT_BY_POS,MODE_HISTORY)) { LastLot=OrderLots(); if((OrderMagicNumber()==MagicNumber)&&(OrderProfit()<0)) Multiplier=MultiplierLot; if((OrderMagicNumber()==MagicNumber)&&(OrderProfit()>=0)) Multiplier=1; } } } //------------------------------------------------------ //lot size if(Multiplier>1) Lot=NormalizeDouble(MathMin(MathMax(LastLot*Multiplier,MinLot),MaxLot),LotDigit); else Lot=NormalizeDouble(MathMin(MathMax(LotSize*Multiplier,MinLot),MaxLot),LotDigit); //------------------------------------------------------ return(Lot); }
Do not try that code.
- Never use NormalizeDouble Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
if(LotStep==1)LotDigit=0; if(LotStep==0.1)LotDigit=1; if(LotStep==0.01)LotDigit=2;
This assumes a lotStep a power of ten and fails for all others Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum- Account free margin has nothing to do with risk. Wanted risk = account balance * percentage. Actual risk = lot size * (orderOpenPrice - ISL) * deltaPerPoint. Set your SL, then solve for lot size. THEN verify you have enough free margin at the most adverse excursion (i.e. SL) for ALL open orders to avoid a margin call. See my code
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, would you please help me with the code for increasing lot if market order closed with a loss and lot to stay the same if market order closed with profit.
for an example if EA start with (0.1 lot ) to trade, lot must increase to 0.2 if market order closed with a loss and to 0.3 lot if market order still closed in a loss. But lot must stay as 0.1 lot as long as market order closed with profit.
I will be glad if I can get a tip on how to solve such a problem.
Thanks