First try at creating EA, not opening any trades...

 

Hi!


I'm currently trying to stich my first EA together and was finally able to compile without any errors. When running the backtest, I can see all the data/indicators I wanted to include showing up properly, but no trades are being executed, even though all conditions are met. I suppose the EA is not able to properly send a trade, here's the snippet where I suspect something odd:


    // Declare MqlTradeRequest and MqlTradeResult variables
MqlTradeRequest request = {};
MqlTradeResult result = {};

// Set trade request parameters
request.symbol = Symbol();

if (Cond1 && Cond2 && Cond3 && Cond4) {
    request.type = ORDER_TYPE_SELL;
    request.action = TRADE_ACTION_DEAL;
    request.sl = FastEMA + StopLossMultiplier * SymbolInfoDouble(Symbol(), SYMBOL_POINT);
    request.tp = CurrentPrice - TakeProfitMultiplier * SymbolInfoDouble(Symbol(), SYMBOL_POINT);
} else if (Cond5 && Cond6 && Cond7 && Cond8){
    request.type = ORDER_TYPE_BUY;
    request.action = TRADE_ACTION_DEAL;
    request.sl = FastEMA - StopLossMultiplier * SymbolInfoDouble(Symbol(), SYMBOL_POINT);
    request.tp = CurrentPrice + TakeProfitMultiplier * SymbolInfoDouble(Symbol(), SYMBOL_POINT);
}

request.volume = TradeSize;
request.price = CurrentPrice;
request.magic = MagicNumber;
request.comment = "Comment";
request.deviation = 0;
request.type_filling = ORDER_FILLING_FOK;

// Send trade request
if (OrderSend(request, result)) {
    Print("Order placed successfully. Ticket: ", result.order);
} else {
    Print("Error placing order. Error code: ", GetLastError());
}
}

I tried to change all my input variables, but no matter if testing live onr on historical data, the EA just won't trade...would really appreciate if anyone with experience can look over what I posted above!


Thanks a lot!

 
Ha.Hoss:

Hi!


I'm currently trying to stich my first EA together and was finally able to compile without any errors. When running the backtest, I can see all the data/indicators I wanted to include showing up properly, but no trades are being executed, even though all conditions are met. I suppose the EA is not able to properly send a trade, here's the snippet where I suspect something odd:


I tried to change all my input variables, but no matter if testing live onr on historical data, the EA just won't trade...would really appreciate if anyone with experience can look over what I posted above!


Thanks a lot!

Use Trade class. No need for complications 
 
Ha.Hoss:

Hi!


I'm currently trying to stich my first EA together and was finally able to compile without any errors. When running the backtest, I can see all the data/indicators I wanted to include showing up properly, but no trades are being executed, even though all conditions are met. I suppose the EA is not able to properly send a trade, here's the snippet where I suspect something odd:


I tried to change all my input variables, but no matter if testing live onr on historical data, the EA just won't trade...would really appreciate if anyone with experience can look over what I posted above!


Thanks a lot!


You can see the relevant error code on the "Experts" tab of the "Toolbox" ... and then search the given code in the documentation.

 
Ha.Hoss:

Hi!


I'm currently trying to stich my first EA together and was finally able to compile without any errors. When running the backtest, I can see all the data/indicators I wanted to include showing up properly, but no trades are being executed, even though all conditions are met. I suppose the EA is not able to properly send a trade, here's the snippet where I suspect something odd:


I tried to change all my input variables, but no matter if testing live onr on historical data, the EA just won't trade...would really appreciate if anyone with experience can look over what I posted above!


Thanks a lot!


Show a screenshot of the error that appears after compilation at here.

 

I'm still trying to figure it out, currently reading through some more tutorials to get a better understanding on what I'm actually doing, heh...

There is no error message, the EA compiles with 0 errors, can be loaded into the backtester and a live chart, everything shows up as supposed, but it just doesn't trade, that's why I suspect that my code section for sending trades posted above is faulty...

 
Ha.Hoss #:

I'm still trying to figure it out, currently reading through some more tutorials to get a better understanding on what I'm actually doing, heh...

There is no error message, the EA compiles with 0 errors, can be loaded into the backtester and a live chart, everything shows up as supposed, but it just doesn't trade, that's why I suspect that my code section for sending trades posted above is faulty...

I understand you dont get any errors when compiling, but do you get any errors in your logs when backtesting? Backtest and then click "Journal", see if there is any failed trades.
 
super1m #:
I understand you dont get any errors when compiling, but do you get any errors in your logs when backtesting? Backtest and then click "Journal", see if there is any failed trades.
I see, that's what you mean, sorry for the confusion. The journal is also clean of any errors, that's why I don't really have a solid starting point to figure out what is at fault here...
 
Print your Cond1 and Cond2 … … check if they are all true … if they are then use Trade class for opening trades , if is working with Trade class then you investigate further your code 
 
Ha.Hoss:

Hi!


I'm currently trying to stich my first EA together and was finally able to compile without any errors. When running the backtest, I can see all the data/indicators I wanted to include showing up properly, but no trades are being executed, even though all conditions are met. I suppose the EA is not able to properly send a trade, here's the snippet where I suspect something odd:


I tried to change all my input variables, but no matter if testing live onr on historical data, the EA just won't trade...would really appreciate if anyone with experience can look over what I posted above!


Thanks a lot!

By trade class they mean 

#include <Trade/Trade.mqh>
//...Global variable

CTrade trade;

void OnTick()
{
if (PositionsTotal()==0) //Condition so that only one trade is opened at once
{trade.Buy(0.10,NULL); //This opens a buy position
}
}
Reason: