expert advisor - miscellaneous questions - page 31

 
Max Enrik:


if
(id==CHARTEVENT_OBJECT_CLICK && (StringFind(sparam,Button_1,0)>=0 || StringFind(sparam,Button_2,0)>=0))
  {
   ticketnumber=(int) StringSubstr(sparam,1);

   Print(ticketnumber);

Print your ticket number - make sure it looks correct.

-----

Max Enrik:

if(id==CHARTEVENT_OBJECT_CLICK && (StringFind(sparam,Button_1,0)>=0 || StringFind(sparam,Button_2,0)>=0))
  {
   ticketnumber=(int) StringSubstr(sparam,1);

   if(OrderSelect(ticketnumber,SELECT_BY_TICKET))
     {
      if(StringFind(sparam,Button_1,0)>=0)
        {
         // ...
        }

      if(StringFind(sparam,Button_2,0)>=0)
        {
         //...
        }

      for(i=OrdersTotal()-1; i>=0; i--)
        {
         if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
         if(Symbol()!=OrderSymbol()) continue;

         update_1();
         update_2();
         update_3();
        }
     }
   else printf("OrderSelect failed for %i",ticketnumber); 

}

Check the OrderSelect is working.

-----

Max Enrik:
if(id==CHARTEVENT_OBJECT_CLICK && (StringFind(sparam,Button_1,0)>=0 || StringFind(sparam,Button_2,0)>=0))
  {
   ticketnumber=(int) StringSubstr(sparam,1);

   if(OrderSelect(ticketnumber,SELECT_BY_TICKET))
     {
      if(StringFind(sparam,Button_1,0)>=0)
        {
         // ...
        }

      if(StringFind(sparam,Button_2,0)>=0)
        {
         //...
        }

      for(i=OrdersTotal()-1; i>=0; i--)
        {
         if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
         if(Symbol()!=OrderSymbol()) continue;

         update_1();
         update_2();
         update_3();

        }
     }
  }

I don't understand this.

You know this goes through every order with the same Symbol and runs update_1() update_2() update_3()? Not just the order you found with ticketnumber.

 
honest_knave:

Print your ticket number - make sure it looks correct.
-----
Check the OrderSelect is working.
-----
I don't understand this.
You know this goes through every order with the same Symbol and runs update_1() update_2() update_3()? Not just the order you found with ticketnumber.

Thanks for your prompt comment.
After your comment, I checked once again. It looks good.

#1 - Ticket number - correct.
#2 - OrderSelect() works.
#3 - Yeah! you right, but if I do not use it that update_*()'s won't works.

I use that method for Drags, that method works good. But that method does not works good for CHARTEVENT_OBJECT_CLICK. ( it does work good while single order, when I open opposite order it does works. )

I really need help, please. 

 
Show me a screenshot of what you want to happen. I'm not clear on the problem.
 
honest_knave:
Show me a screenshot of what you want to happen. I'm not clear on the problem.

While I was making screenshot I found solution, just wow! ( I already spent over 2 hours for it )
So, it looks like good so far, if something will go to wrong about that I will write more clearly comment.

Thanks for your time.

( That was really magical. )

 
Max Enrik:

While I was making screenshot I found solution, just wow! ( I already spent over 2 hours for it )
So, it looks like good so far, if something will go to wrong about that I will write more clearly comment.

Thanks for your time.

( That was really magical. )

I'm glad you got it fixed
 

#Profit Currency Calculate - Open

I just started to find solution that how can I calculate Profit in Currency. e.g: 100 pip = 0.89 USD in USDJPY

Q:  How can I convert Order Profit in pips to Order Profit in Currency, please?

( I just worry about I can't find solution till market close )

Any clearly comment would be better, please.

Thanks in advance.

//--- 2nd times edited

I found a lot of similar forums, but I can't find this type of topics. 

 

How do you get to profit in pips?

OrderProfit()

Returned value:

The net profit value (without swaps or commissions) for the selected order.

For open orders, it is the current unrealized profit.

For closed orders, it is the fixed profit.

 
Marco vd Heijden:

How do you get to profit in pips?

OrderProfit()

Returned value:

The net profit value (without swaps or commissions) for the selected order.

For open orders, it is the current unrealized profit.

For closed orders, it is the fixed profit.

Thanks for your comment. 

Sorry Marco, I did not describe my issue more clearly.
I can easily get value Order Profit in Pips and Currency - with below codes.

DoubleToString( OrderProfit(), 2 )
DoubleToString( change_to_points( Bid - OrderOpenPrice() ), 0 );

But I try to find solution for Stop Loss and Take Profit in Currency.

I am working on it, and I still need help, please. 

Thanks in advance.

 
Max Enrik: ut I try to find solution for Stop Loss and Take Profit in Currency.
Substitute OrderStopLoss for one of those.
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  • Do NOT use TickValue by itself - DeltaPerLot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out
 
whroeder1:
Substitute OrderStopLoss for one of those.
  • You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
  • Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around $10/pip but it takes account of the exchange rates of the pair vs. your account currency.)
  • Do NOT use TickValue by itself - DeltaPerLot
  • You must normalize lots properly and check against min and max.
  • You must also check FreeMargin to avoid stop out

Thanks for your more informative comment.
I am studying it... 

//--- 2nd time edited

Maybe lack of code knowledge does not gives me permission to understand your calculation method.
But I think I close to solution. And I try below code that I get ( for Buy Order ) Stop Loss in Currency.
Then I get this results ( I know I passed something... because I can't imply them... ) e.g: Profits: 7.67 USD - Pips: 1001 /  for USDCAD. But actually Profit: 7.69 USD. ( I already checked out ( Swap and Commission ) )

double  tickvalue               = MarketInfo( Symbol(), MODE_TICKVALUE ) / MarketInfo( Symbol(), MODE_TICKSIZE ),
        buy_stoploss_incurrency = OrderOpenPrice() - OrderStopLoss();
string  stoploss_incurrency     = DoubleToString( OrderLots() * buy_stoploss_incurrency * tickvalue + OrderCommission(), 2 );

Print( "stop loss in currency: ", stoploss_incurrency );

So, I need advice, please.

Thanks in advance.

//--- 3rd time edited

Please coder or programmer let me know above code is right? Because now I see correct Stop Loss in currency for GBPCHF, but not correct for USDCAD. I do not figure out what is wrong?! ( note: USDCAD open position, but GBPCHF is Pending orders. )

Everything is OK for now. So, thanks a lot Mr. William.

Reason: