Really Working SL Calculation Sub-program:
double CalculateStopLoss(double Price_Open, ENUM_ORDER_TYPE Order_Type) {
double Digits=-SymbolInfoInteger(SymbolName,SYMBOL_DIGITS),
Lots=InitVolume*100000,SL=0,Pips=MathPow(10,Digits);
LastDeal.PipSize=Lots*Price_Open*(Pips/Price_Open);
if(Order_Type==ORDER_TYPE_BUY) SL=Price_Open-Pips*InitMaxLoss/LastDeal.PipSize;
else SL=Price_Open+Pips*InitMaxLoss/LastDeal.PipSize;
FlagPrint(5," Pips: " + DoubleToString(Pips) +
" Price_Open: " + DoubleToString(Price_Open) +
" Lots: " + DoubleToString(Lots,0) +
" PipSize: " + DoubleToString(LastDeal.PipSize,2) +
" SL: " + DoubleToString(SL));
return(SL);}
I hope that one who is interested understands here undeclared variables e.t.c.
Really Working SL Calculation Sub-program:
double CalculateStopLoss(double Price_Open, ENUM_ORDER_TYPE Order_Type) {
double Digits=-SymbolInfoInteger(SymbolName,SYMBOL_DIGITS),
Lots=InitVolume*100000,SL=0,Pips=MathPow(10,Digits);
LastDeal.PipSize=Lots*Price_Open*(Pips/Price_Open);
if(Order_Type==ORDER_TYPE_BUY) SL=Price_Open-Pips*InitMaxLoss/LastDeal.PipSize;
else SL=Price_Open+Pips*InitMaxLoss/LastDeal.PipSize;
FlagPrint(5," Pips: " + DoubleToString(Pips) +
" Price_Open: " + DoubleToString(Price_Open) +
" Lots: " + DoubleToString(Lots,0) +
" PipSize: " + DoubleToString(LastDeal.PipSize,2) +
" SL: " + DoubleToString(SL));
return(SL);}
I hope that one who is interested understands here undeclared variables e.t.c.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When I make deal, then I know (risk) sum of money what I can loose (in program (OrderCalcProfit()) that is Profit with minus of course). But when I want to put that sum in EA I need StopLoss Price. I thought I can calculate it with cycling:
double CalculateStopLoss(double Price_Open, double Side, ENUM_ORDER_TYPE Order_Type) {double Price_Close=0.0,Profit=0.0,SL=0.0; uint i;Increment=10e-6;
if(Side=="Up") Increment=-Increment;
FlagPrint(0," Open Price: " + DoubleToString(Price_Open,7));
for(i=0;i<100000;i++) {
Price_Close=Price_Open+i*Increment;
OrderCalcProfit(Order_Type,SymbolName,InitMaxLoss,Price_Open,Price_Close,Profit);
if(MathAbs(Profit)>InitMaxLoss) {SL=Price_Close;break;};}
if(i=100000) FlagPrint(0," Warning: StopLoss index reached to extreme limit, Profit:" + DoubleToString(Profit) );
else FlagPrint(0," Calculate StopLoss Result: " + DoubleToString(SL,7) + ", Profit: " + DoubleToString(Profit) );
return(SL);}
There InitMaxLoss is sum what I can loose, (Deal)Side is "Up" or "Down" accordingly with "BUY" or "SELL". That function almost always reaches to maximum index 100000 and overall was yet unable to give reliable result. (So I need turned around formula of OrderCalcProfit().)
Maybe in some good day I can get good result with that, but can anybody give me better way to calculate StopLoss (Depending of the loss (or risk) sum)?