Error type cannot convert enum

Joseph Kachimba
49

All need a help with converting type to enum in the code below

input int                  InpMagicNumber  = 1111;            // Magic Number

input string               InpTradeComment = __FILE__;        // Trade Comment

input double               InpVolume       = 0.001;            // Volume per order


ENUM_POSITION_TYPE CurrentTrade;

#include <Trade/Trade.mqh>

CTrade Trade;

CPositionInfo PositionInfo;


int OnInit(){


CurrentTrade = -1;


   Trade.SetExpertMagicNumber(InpMagicNumber);   


   return(INIT_SUCCEEDED);

}


void OnDeinit(const int reason){

}


void OnTick(){

if ( CurrentTrade >= 0 ) return;


double lastClose = iClose( Symbol(), Period(), 1);


double bid  = SymbolInfoDouble( Symbol(), SYMBOL_BID);

if ( bid>lastClose ) {

        CurrentTrade = OpenTrade( POSITION_TYPE_BUY,0);

        }else if ( bid<lastClose ) {

CurrentTrade = OpenTrade( POSITION_TYPE_SELL,0);

}

}


ENUM_POSITION_TYPE OpenTrade( ENUM_POSITION_TYPE type, double sl) {


double price = ( type == POSITION_TYPE_BUY) ? SymbolInfoDouble( Symbol(), SYMBOL_ASK)

  : SymbolInfoDouble( Symbol(), SYMBOL_BID);

if ( Trade.PositionOpen( Symbol(), type, InpVolume, price, sl, 0, InpTradeComment )) {

          return ( ( ENUM_POSITION_TYPE ) type );

       }

return ( -1 );

}

Joseph Kachimba
49
Joseph Kachimba  

@Vladimir Karputov

would you please look at and assist what am getting wrong

Paul Anscombe
7357
Edit your post and use the code button <|> to add code so it is readable 
And provide the specific error details
R4tna C
380
R4tna C  

The line where you get the error is:

if ( Trade.PositionOpen( Symbol(), type, InpVolume, price, sl, 0, InpTradeComment ))

Place the cursor on PositionOpen and press Alt+G - this takes you to the declaration:

bool CTrade::PositionOpen(const string symbol,const ENUM_ORDER_TYPE order_type,const double volume,
                          const double price,const double sl,const double tp,const string comment)


You will see that PositionOpen() accepts ENUM_ORDER_TYPE whereas you are sending ENUM_POSITION_TYPE hence the mismatch.

You need to write some logic to translate from position type to order type

Tobias Johannes Zimmer
1249
Why is this topic in the stocks, futures, options section anyways?
Keith Watford
Moderator
36102
Tobias Johannes Zimmer #:
Why is this topic in the stocks, futures, options section anyways?

Because people often tend to just post anywhere and are totally unconcerned whether they are posting in the relevant sections.

I used to move topics to the correct sections, but it was taking so much of my time I stopped doing that a few months ago.

Tobias Johannes Zimmer
1249
Keith Watford #:

Because people often tend to just post anywhere and are totally unconcerned whether they are posting in the relevant sections.

I used to move topics to the correct sections, but it was taking so much of my time I stopped doing that a few months ago.

Oh. Yeah that's bad. I am hoping that people realize that this is a forum and it has its order.
One should suppose that everybody knows how to behave in a forum in the year 2022, but reality proves us wrong.