@Vladimir Karputov
would you please look at and assist what am getting wrong
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
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.
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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 );
}