From 1b27d50585242dbc679c37df9994a7b0f02480b5 Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 23 Apr 2024 22:15:55 +0100 Subject: [PATCH] Moves enum macros into the main file and fixes compilation errors --- Trade/TradeSignal.struct.h | 7 ++ Trade/tests/TradeSignalEnumMacro.test.mq5 | 86 ++++++++++------------- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index 77918c1fd..17854cd58 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -50,6 +50,13 @@ #define SIGNAL_OPEN_TIME_FILTER STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER) #define SIGNAL_OPEN_UPWARDS STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_OPEN_UPWARDS) +// All the following macro return true if the main signal is activated +// AND the filter is not activated AND the time filter is not activated. +#define TRADE_SIGNAL_IS_CLOSE_BUY(x) (((x & SIGNAL_CLOSE_BUY_MAIN) != 0) && !(x & (SIGNAL_CLOSE_BUY_FILTER | SIGNAL_CLOSE_TIME_FILTER))) +#define TRADE_SIGNAL_IS_CLOSE_SELL(x) (((x & SIGNAL_CLOSE_SELL_MAIN) != 0) && !(x & (SIGNAL_CLOSE_SELL_FILTER | SIGNAL_CLOSE_TIME_FILTER))) +#define TRADE_SIGNAL_IS_OPEN_BUY(x) (((x & SIGNAL_OPEN_BUY_MAIN) != 0) && !(x & (SIGNAL_OPEN_BUY_FILTER | SIGNAL_OPEN_TIME_FILTER))) +#define TRADE_SIGNAL_IS_OPEN_SELL(x) (((x & SIGNAL_OPEN_SELL_MAIN) != 0) && !(x & (SIGNAL_OPEN_SELL_FILTER | SIGNAL_OPEN_TIME_FILTER))) + // Structure for a trade signal. struct TradeSignalEntry { protected: diff --git a/Trade/tests/TradeSignalEnumMacro.test.mq5 b/Trade/tests/TradeSignalEnumMacro.test.mq5 index 2153d026d..f198433b0 100644 --- a/Trade/tests/TradeSignalEnumMacro.test.mq5 +++ b/Trade/tests/TradeSignalEnumMacro.test.mq5 @@ -22,59 +22,51 @@ #include #include - -// all the following macro return true if the main signal is activated AND the filter is not activated AND the time filter is not activated -#define TRADE_SIGNAL_IS_CLOSE_BUY(x) ((x & TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN) && !(x & (TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER))) -#define TRADE_SIGNAL_IS_CLOSE_SELL(x) ((x & TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN) && !(x & (TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER))) -#define TRADE_SIGNAL_IS_OPEN_BUY(x) ((x & TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN) && !(x & (TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER))) -#define TRADE_SIGNAL_IS_OPEN_SELL(x) ((x & TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN) && !(x & (TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER))) - int testEnum(){ uint s; - - s = TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==true ,"Fail!"); - s = TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN | TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN | 0 | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_CLOSE_BUY_MAIN | TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); - s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); - s = 0 | 0 | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_CLOSE_BUY_FILTER | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); - - s = TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN| 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==true ,"Fail!"); - s = TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN| TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER| 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN| 0 | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_CLOSE_SELL_MAIN| TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER| TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); - s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER| 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); - s = 0 | 0 | TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_CLOSE_SELL_FILTER| TRADE_SIGNAL_FLAG_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); + s = SIGNAL_CLOSE_BUY_MAIN | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==true ,"Fail!"); + s = SIGNAL_CLOSE_BUY_MAIN | SIGNAL_CLOSE_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); + s = SIGNAL_CLOSE_BUY_MAIN | 0 | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); + s = SIGNAL_CLOSE_BUY_MAIN | SIGNAL_CLOSE_BUY_FILTER | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); + s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); + s = 0 | SIGNAL_CLOSE_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); + s = 0 | 0 | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); + s = 0 | SIGNAL_CLOSE_BUY_FILTER | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_BUY(s)==false,"Fail!"); + + s = SIGNAL_CLOSE_SELL_MAIN | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==true ,"Fail!"); + s = SIGNAL_CLOSE_SELL_MAIN | SIGNAL_CLOSE_SELL_FILTER| 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); + s = SIGNAL_CLOSE_SELL_MAIN | 0 | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); + s = SIGNAL_CLOSE_SELL_MAIN | SIGNAL_CLOSE_SELL_FILTER | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); + s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); + s = 0 | SIGNAL_CLOSE_SELL_FILTER| 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); + s = 0 | 0 | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); + s = 0 | SIGNAL_CLOSE_SELL_FILTER | SIGNAL_CLOSE_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_CLOSE_SELL(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==true ,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN | TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN | 0 | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_BUY_MAIN | TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); - s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); - s = 0 | 0 | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_OPEN_BUY_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==true ,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN | TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN | 0 | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); - s = TRADE_SIGNAL_FLAG_OPEN_SELL_MAIN | TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); - s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); - s = 0 | 0 | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); - s = 0 | TRADE_SIGNAL_FLAG_OPEN_SELL_FILTER | TRADE_SIGNAL_FLAG_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); + s = SIGNAL_OPEN_BUY_MAIN | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==true ,"Fail!"); + s = SIGNAL_OPEN_BUY_MAIN | SIGNAL_OPEN_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); + s = SIGNAL_OPEN_BUY_MAIN | 0 | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); + s = SIGNAL_OPEN_BUY_MAIN | SIGNAL_OPEN_BUY_FILTER | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); + s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); + s = 0 | SIGNAL_OPEN_BUY_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); + s = 0 | 0 | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); + s = 0 | SIGNAL_OPEN_BUY_FILTER | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_BUY(s)==false,"Fail!"); + + s = SIGNAL_OPEN_SELL_MAIN | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==true ,"Fail!"); + s = SIGNAL_OPEN_SELL_MAIN | SIGNAL_OPEN_SELL_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); + s = SIGNAL_OPEN_SELL_MAIN | 0 | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); + s = SIGNAL_OPEN_SELL_MAIN | SIGNAL_OPEN_SELL_FILTER | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); + s = 0 | 0 | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); + s = 0 | SIGNAL_OPEN_SELL_FILTER | 0 ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); + s = 0 | 0 | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); + s = 0 | SIGNAL_OPEN_SELL_FILTER | SIGNAL_OPEN_TIME_FILTER ; assertTrueOrFail(TRADE_SIGNAL_IS_OPEN_SELL(s)==false,"Fail!"); return INIT_SUCCEEDED; } -void OnStart(){ - if (testEnum()==INIT_SUCCEEDED){ - Print("Test passed!"); - } else { - Print("Test failed!"); - } +/** + * Implements OnInit(). + */ +int OnInit() { + return testEnum(); }