calculate sum of StopLoss over multiple charts on different timeframe

 

Hi, is it possible to calculate the sum of total StopLoss distance using one EA on different pairs with different timeframes

e.g 4x charts: M30 EURUSD, H1 EURUSD, M30 USDJPY, H1 USDJPY using the same EA with different Magic number

Could anyone please advise if I can get the "total StopLoss distance" for all the orders opened on the terminal?

With many thanks in advance!!

 
Yes you can. If you know how to find the distance for one pair then save the value in a terminal variable and keep adding.
 
ubzen:
Yes you can. If you know how to find the distance for one pair then save the value in a terminal variable and keep adding.

hi ubzen, thanks for your reply

step 1. If you know how to find the distance for one pair - understand, FUNCTION: TotalSL=GetTotalSL(); is done.

step 2. save the value in a terminal variable and keep adding.

Could you please give an example on what you mean here, this part is new to me

thanks again

 

On second taught you don't really need the Terminal variable.

void start(){
    double Ans=0.0;
    for(int i=OrdersTotal()-1;i>=0;i--){
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
            if(OrderStopLoss()>0){
                Ans+=MathAbs(OrderOpenPrice()-OrderStopLoss());
            }
        }
    }
    Print("Total Stop Distance in Points="+Ans);
}

The above code is not Fail_Safe. Just giving as Sample. Something like that will loop through all open orders on every tick on every chart to obtain the total distance. If you want to optimize, you could limit by looping only when the Last_OrderTotal is != OrdersTotal.

 

hi ubzen, thanks for your reply

above code won't work for my case as my SL is dynamically calculated

i.e. when OrderSend(), I use a larger SL distance and relies on the EA to dynamically monitoring if the real SL is hit (Close[1] vs. trendline on the graph)

therefore, I need each EA(unique Magic#) to calculate their own TotalSL();

 
Well then add if(OrderMagic#()==iMagic). If you want to Filter by timeFrame and Symbols.. Then add those as well. Like I said its not Fail_Safe. Its not written so that you can just copy and paste.
 
ubzen:
Well then add if(OrderMagic#()==iMagic). If you want to Filter by timeFrame and Symbols.. Then add those as well. Like I said its not Fail_Safe. Its not written so that you can just copy and paste.

Sorry I am confused

Doesn't above only return the Total Stop Distance of 1 chart?

How to get the sum of the 4x charts

TotalSL for M30 EURUSD=A // need to obtain values B, C, D from other charts to get sum(A, B, C, D)

TotalSL for H1 EURUSD=B

TotalSL for M30 USDJPY=C

TotalSL for H1 USDJPY=D

Could you please advise how to use "terminal variable" in this case, thanks.
 
holdenmcgorin:

Sorry I am confused

Doesn't above only return the Total Stop Distance of 1 chart?

That's what you asked for . . .

"therefore, I need each EA(unique Magic#) to calculate their own TotalSL();"

 
RaptorUK:

That's what you asked for . . .

"therefore, I need ;each EA(unique Magic#) to calculate their own TotalSL()"

what I meant was:

I've already done each EA (unique Magic#) to calculate their own TotalSL()

what I need to ask is how to get

TotalSLOver4Charts= TotalSLForChart1(Magic#100)

+TotalSLForChart2(Magic#200)

+TotalSLForChart3(Magic#300)

+TotalSLForChart4(Magic#400)

 
holdenmcgorin:

what I meant was:

I've already done each EA (unique Magic#) to calculate their own TotalSL()

what I need to ask is how to get

TotalSLOver4Charts= TotalSLForChart1(Magic#100)


OK, I think you have 2 options:

1. Get each EA to calculate the TotalSL for it's Orders and then also get it to calculate the total SL for ALL EA placed orders

2. Get each EA to store it's own orders TotalSL in a Global variable then each EA can read the Global variables and add them to get the TotalSL across all EA placed Orders.

I would go for option 1. The implementation of this will depend on the structure of your Magic Numbers.

 
void start(){
    double Ans=0.0;
    for(int i=OrdersTotal()-1;i>=0;i--){
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
            if(OrderMagicNumber()==100
            || OrderMagicNumber()==200
            || OrderMagicNumber()==300
            || OrderMagicNumber()==400
            ){
                if(OrderStopLoss()>0){
                    Ans+=MathAbs(OrderOpenPrice()-OrderStopLoss());
                }
            }
        }
    }
    GlobalVariableSet("Total_Stop_Distance",Ans);
    Print("Total Stop Distance in Points="+Ans);
}