Calculating Price Target

 

Hi,I want to set up a TP on my ea, which equals (High[2]-Low[2])*1.5

Which is simply put range of a certain bar multplied by 1.5..

My question is How do I type it correctly because it seems that i make a calculation error. Thank you.

  for(int s=OrdersTotal()-1;s>=0;s--)
  {
    if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber()==MagicNumber)
        if(OrderSymbol()==Symbol())
          if(OrderType()==OP_SELL)
            OrderModify(OrderTicket(),OrderOpenPrice(),High[2]+3*Point,(High[2]-Low[2])*1.5,0,Brown);
 
Redael777:

Hi,I want to set up a TP on my ea, which equals (High[2]-Low[2])*1.5

Which is simply put range of a certain bar multplied by 1.5..

My question is How do I type it correctly because it seems that i make a calculation error. Thank you.

For a Sell you can't set the TP higher than the current price . . . you need to check before you try to modify the order . . . you also need to check the return value from your Trading Functions and if they fail report the error and any relevant variables: What are Function return values ? How do I use them ?

This is what your code needs to check before placing or modifying Orders: Requirements and Limitations in Making Trades
 

Thank you for the reply.

I meant Bid - (High[2]-Low[2])*1.5, will that do? what should I add?

 
Redael777:

Thank you for the reply.

I meant Bid - (High[2]-Low[2])*1.5, will that do? what should I add?

You need to check to see if that price complies with this: Requirements and Limitations in Making Trades <--- click this and read . . .
 

ok i will play with stoplevel etc, but more important for me is the arithmetics, when i tried to print out(using Comment) this (High[2]-Low[2])*1.5 it gave me 0...

so this is what i am confused with.Thanks again,please advice.

 
Redael777:

ok i will play with stoplevel etc, but more important for me is the arithmetics, when i tried to print out(using Comment) this (High[2]-Low[2])*1.5 it gave me 0...

so this is what i am confused with.Thanks again,please advice.

If you have a bar with no movement High equals Low so High - Low = 0.0
 
so how should i calculate barlength that is already finished..?
 
Redael777:
so how should i calculate barlength that is already finished..?
You are calculating it correctly . . . but if High == Low the length is 0.0
 
Redael777:

ok i will play with stoplevel etc, but more important for me is the arithmetics, when i tried to print out(using Comment) this (High[2]-Low[2])*1.5 it gave me 0...

so this is what i am confused with.Thanks again,please advice.


Are you using (High[2]-Low[2])*1.5 directly for your print ?

If you are saving it as an int variable and then printing the variable, you would often see 0, so save it as a double

Reason: