Skip to content

Commit

Permalink
Moves enum macros into the main file and fixes compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Apr 23, 2024
1 parent 1c1d0d9 commit 30698b1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
7 changes: 7 additions & 0 deletions Trade/TradeSignal.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
82 changes: 37 additions & 45 deletions Trade/tests/TradeSignalEnumMacro.test.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,51 @@
#include <EA31337-classes/Test.mqh>
#include <EA31337-classes/Trade/TradeSignal.struct.h>


// 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 = 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 = 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_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 = 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 = 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_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();
}

0 comments on commit 30698b1

Please sign in to comment.