expert advisor - miscellaneous questions - page 32

 

( Before I try to write this comment, I think I researched wildly for find solution, yeah I found similar threads, but I did not find solution for this issue. )

I use below code for Sell Order that show me Stop Loss in pips, it show me correct value till when Stop Loss turns to Positive.
So, I have not any idea that how I can try something to solve this issue.

Any good comment, would be better, please.
( note: I am not using Trailing Stop for now. Also below code just for Info Updates, not for OrderSend() or similar things. )

if(OrderType()==OP_SELL || (OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP))
  {
   riskinpips=change_to_pips(OrderStopLoss()-OrderOpenPrice());
  }
Print("stop loss in pips",DoubleToString(riskinpips,2));

Thanks in advance. 

When Stop Loss in Positive Profit 

( note: screenshot labels made by photo edition program for describe my issue )
 

Well it's the highest value minus the lowest value that give you the result so you can check which one is the highest

if(OrderStopLoss()>OrderOpenPrice())
{
  // orderstoploss - orderopenprice
}

else if(OrderOpenPrice()>OrderStopLoss())
{
  // orderopenprice - orderstoploss
}
 
Marco vd Heijden:

Well it's the highest value minus the lowest value that give you the result so you can check which one is the highest

if(OrderStopLoss()>OrderOpenPrice())
{
  // orderstoploss - orderopenprice
}

else if(OrderOpenPrice()>OrderStopLoss())
{
  // orderopenprice - orderstoploss
}

I just laughing myself that I never mind it. I think this could help me. Soon I will trying it.

Thanks a lot Mr. Marco

 

#Profit Currency Calculate - Closed

It works perfect so far.
Thanks a lot @Marco vd Heijden and @whroeder1

 

#Time - Open

Since I started to research about Time / Clock for my EA. I see authors use start() JUST in indicator for it.
I use OnTimer() and OnTick() in my EA, I would not like to use start().
So I just need to be sure / learn which special function would be better for Time and Clock function?

I will continue to research about this issue 10 hours later.
( note: I already found few Time and Clock indicators from Mql5.com Codebase page - but I do not like to copy and paste )

Any good comments, forum share, and links and something else would be better for me.

Thanks in advance.

 

The start function is replaced by OnStart only in scripts. In Expert Advisors and indicators it should be renamed to OnTick and OnCalculate, respectively. The code that is to be executed during a mql5 program operation should be located in these three functions:

See: https://www.mql5.com/en/docs/migration

Documentation on MQL5: Moving from MQL4
Documentation on MQL5: Moving from MQL4
  • www.mql5.com
Moving from MQL4 - Reference on algorithmic/automated trading language for MetaTrader 5
 
Marco vd Heijden:

The start function is replaced by OnStart only in scripts. In Expert Advisors and indicators it should be renamed to OnTick and OnCalculate, respectively. The code that is to be executed during a mql5 program operation should be located in these three functions:

Thanks so much more @Marco this common so informative for me. I already read " Moving from MQL4 to MQL5 ".
 
Max Enrik:

#Time - Open

Since I started to research about Time / Clock for my EA. I see authors use start() JUST in indicator for it.
I use OnTimer() and OnTick() in my EA, I would not like to use start().
So I just need to be sure / learn which special function would be better for Time and Clock function?

I will continue to research about this issue 10 hours later.
( note: I already found few Time and Clock indicators from Mql5.com Codebase page - but I do not like to copy and paste )

Any good comments, forum share, and links and something else would be better for me.

Thanks in advance.

Use OnTimer().

Using TimeLocal() will give a better appearance, but it will not be synced to broker timezone.

Using TimeCurrent() will be synced to your broker, but may lag then "jump" seconds depending on when ticks arrive. This example will highlight the problem:

#property strict

int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }

void OnTimer()
  {
   Comment(StringFormat("%s - Local\n%s - Broker",TimeToString(TimeLocal(),TIME_SECONDS),TimeToString(TimeCurrent(),TIME_SECONDS)));
  }


 

 

#Time - Closed

honest_knave:

Use OnTimer().
Using TimeLocal() will give a better appearance, but it will not be synced to broker timezone.
Using TimeCurrent() will be synced to your broker, but may lag then "jump" seconds depending on when ticks arrive. This example will highlight the problem:

#property strict

int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }

void OnTimer()
  {
   Comment(StringFormat("%s - Local\n%s - Broker",TimeToString(TimeLocal(),TIME_SECONDS),TimeToString(TimeCurrent(),TIME_SECONDS)));
  }
Completely useful comment. Thanks a lot man.
 

Forum on trading, automated trading systems and testing trading strategies

expert advisor - miscellaneous questions

honest_knave, 2016.11.30 01:28

IMHO it would be better if you kept all your lot calculations together, rather than splitting them between OnChartEvent() and _lotCalc(). One function that checks min / max / step and does the increment / decrement.

void OnChartEvent(const int      id     , // Event ID
                  const long   & lparam , // Parameter of type long event
                  const double & dparam , // Parameter of type double event
                  const string & sparam   // Parameter of type string events
                  )
{
    _lotCalc();
    //-------Process Button---------------------------------------------------------|
    if ( sparam == _btnLotMinus )
    {
        ObjectSetInteger( 0, sparam, OBJPROP_STATE, false );
        _lotSize = fmax(_lotMin, _lotSize-_lotStep);
        _calcUpdade( CALC_CHANGE_LOT );
        printf( " | Lot: %.2f  ", _lotSize );
        return;
    }   //---if Close
    //                          ...
}

void _lotCalc()
{
    //---
    _lotMin  = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  );
    _lotMax  = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  );
    _lotStep = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );

    //---
}

#Lot Step - ReOpen

@honest_knave - thanks for your greatest help about Lot Size and Lot Step.

So I just need to improve this part of code for when " Lot Size >= ( Lot Step * 100 ) " that Lot Step increase by " Lot Step * 100 "

// lot plus
if(sparam==lotbuttonplus)
  {
   if(lotsize>=(lotstep*100))
     {
      lotstep=lotstep*100;
      Print("lot step: ",lotstep);
     }

   lotmaxdivide=lotmax/lotmax *(lotvalue*10);
   lotsize=fmin(lotmaxdivide,lotsize+(( ctrlfalse) ? lotstep*10 : lotstep));

// global variable
   infoupdate();

   printf("Lot: %.2f ",lotsize);
   ObjectSetInteger(0,sparam,OBJPROP_STATE,false);
   return;
  }

Thanks in advance.

Reason: