double MartingaleLevel(double lastlot) //pass lastlot parameter from your calculatelots() function { if(lastlot < martingaleL1) return(martingaleL1); if(lastlot < martingaleL2) return(martingaleL2); if(lastlot < martingaleL3) return(martingaleL3); if(lastlot < martingaleL4) return(martingaleL4); //etc if(lastlot < martingaleL20) return(martingaleL20); return(0); //oops !! if we got here we probably just blew the account; }
looking at what you posted as I thought it would function more as my limited knowledge about mq4 could do not work.
I think it gave little information could you make it clearer
extern string gen="----General inputs----"; extern double Lot=0.01; etc.. extern string mi="====Martingale inputs----"; extern bool UseMartingale=true; extern double MartingaleL6=2.0; extern double MartingaleL7=4.4; extern double MartingaleL8=7.3; extern double MartingaleL9=10.8; extern double MartingaleL10=14.9; extern double MartingaleL11=19.9; extern double MartingaleL12=25.9; extern double MartingaleL13=33.1; extern double MartingaleL14=41.7; extern double MartingaleL15=52.0; extern double MartingaleL16=64.4; extern double MartingaleL17=79.3; extern double MartingaleL18=107.2; extern double MartingaleL19=128.6; extern double MartingaleL20=154.3;
double CalculateLotSize() { //Calculate Martingale lot size if (!UseMartingale) return(Lot); //Find most recent trade if (OrdersHistoryTotal() == 0) return(Lot); double SendLots = Lot; for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--) { if (!OrderSelect(cc, SELECT_BY_POS, MODE_HISTORY) ) continue; if (OrderSymbol() != Symbol() ) continue; if (OrderMagicNumber() != MagicNumber) continue; if (OrderProfit() < 0) { double LotStep = MarketInfo(Symbol(),MODE_LOTSTEP); double digit = 0; if (LotStep == 0.1) digit = 1; if (LotStep == 0.01) digit = 2; SendLots = NormalizeDouble(OrderLots() * MartingaleLotMultiplier, digit); }//if (OrderProfit() < 0) break; }//for (int cc = OrdersHistoryTotal() - 1; cc >= 0; cc--) //Check maximum lots allowed filter in the Martingale section if (SendLots > MaxLotsAllowed) SendLots = Lot; return(SendLots); }//End double CalculateLotSize()
double SendLots = CalculateLotSize();
//Long if (trend == up) { if (!TradeLong) return; //Initial trade tp if (SendLots == Lot && FirstTradeTakeProfit > 0) take = NormalizeDouble(Ask + (FirstTradeTakeProfit * Point), Digits); //Tp for Martingale trades if (SendLots > Lot && SubsequentTakeProfit > 0) take = NormalizeDouble(Ask + (SubsequentTakeProfit * Point), Digits); if (StopLoss > 0) stop = NormalizeDouble(Ask - (StopLoss * Point), Digits); type = OP_BUY; price = Ask; SendTrade = true; }//if (Ask > 1000000) //Short if (trend == down) { if (!TradeShort) return; if (SendLots == Lot && FirstTradeTakeProfit > 0) take = NormalizeDouble(Bid - (FirstTradeTakeProfit * Point), Digits); //Tp for Martingale trades if (SendLots > Lot && SubsequentTakeProfit > 0) take = NormalizeDouble(Bid - (SubsequentTakeProfit * Point), Digits); if (StopLoss > 0) stop = NormalizeDouble(Bid + (StopLoss * Point), Digits); type = OP_SELL; price = Bid; SendTrade = true; }//if (trend == down)
if (SendTrade) { bool result = SendSingleTrade(type, TradeComment, SendLots, price, stop, take); }//if (SendTrade)
The code I gave you in my reply, is an example of a function to return the next one in a sequence of lot sizes held in global variables; martingaleL1 through martingaleL20. When you need to get the next lot size in that sequence pass to it, in a function call, the previous lot size. If you do not know how to do that read, functions
The code I gave you in my reply, is an example of a function to return the next one in a sequence of lot sizes held in global variables; martingaleL1 through martingaleL20. When you need to get the next lot size in that sequence pass to it, in a function call, the previous lot size. If you do not know how to do that read, functions
Someone?
" I think it'll be about 5 days trying to make it work pity me :) "
Would that be a reason to do it not at all ??
If you want someonelse to do it for you then placing a job at Jobs will help you more
If you open a job there for doing this i can help you also if you choose me when i also react as one of the developers
But SDC has given you already a big help here how to solve this problem
If you try to learn yourself to code mq4 and you need some help then you can ask here and with the hints we give
it will for you the help you can get here in how to code and learn to write own programs for MT4
This forum is not the place to ask for coding your programs for free
It is a forum for helping those programmers who wants to learn seriously creating own programs
The Book and some programs in Code Base might help you.
Although I have to warn you about Code Base not all programs there are written well
This Forum is to help you with solving a problem in how to code
I'm sure you can do this if you take the time to learn how to read and program mq4 language
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Usage that code martingale which for multiplying a lot starting with a loss so forth till the MaxLotsAllowed
I wanted to specifically choose the lot for each level martingale.
Example:
Someone can help me, thanks