Skip to content

Commit

Permalink
1.0.6 Added extern SmartExit (default: F). If true, EA will closed AL…
Browse files Browse the repository at this point in the history
…L BUY basket, if

               the pair of TDST Support lines are broken. Conversely, EA will closed ALL
               SELL basket, if the pair of TDST Resistance lines are broken.
            This version is compatible with TDSetup 1.2.3+ or greater.
  • Loading branch information
dennislwm committed Sep 6, 2012
1 parent 9c68df2 commit 0e81f23
Showing 1 changed file with 122 additions and 10 deletions.
132 changes: 122 additions & 10 deletions experts/ForexRed_fifo.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
//| ForexRed.mq4 |
//| Copyright © 2012, Dennis Lee |
//| Assert History |
//| 1.0.5 Added wave +/- FIVE (5). This is compatible with TDSetup 1.2.0+.
//| 1.0.6 Added extern SmartExit (default: F). If true, EA will closed ALL BUY basket, if |
//| the pair of TDST Support lines are broken. Conversely, EA will closed ALL |
//| SELL basket, if the pair of TDST Resistance lines are broken. |
//| This version is compatible with TDSetup 1.2.3+ or greater. |
//| 1.0.5 Added wave +/- FIVE (5). This is compatible with TDSetup 1.2.0+. |
//| 1.0.4 Added extern DebugNotify ( where Debug Level <= ONE (1) ) to notify user on |
//| mobile phone. There is a limit of no more than TWO (2) notifications per |
//| second, and no more than TEN (10) notifications per minute. |
Expand All @@ -24,6 +28,7 @@ extern int Fred2Magic = 12000;
//---- Assert Uni trade direction
extern string s0 = "DoNotTrade: 0:false, 1:sell, -1:buy";
extern int FredDoNotTrade = 0;
extern bool FredSmartExit = false;
extern bool FredDebugNotify= false;
extern int FredDebug = 1;
extern int FredDebugCount = 1000;
Expand All @@ -43,13 +48,21 @@ extern string s4 ="-->PlusGhost Settings<--";
//|------------------------------------------------------------------------------------------|
//| I N T E R N A L V A R I A B L E S |
//|------------------------------------------------------------------------------------------|
string EaName ="ForexRed";
string EaVer ="1.0.5";
string EaName ="ForexRed";
string EaVer ="1.0.6";
int EaDebugCount;
string gTDIsOkUpLineStr;
string gTDIsOk2UpLineStr;
string gTDIsOkDnLineStr;
string gTDIsOk2DnLineStr;
bool isOkUpLine = true;
bool isOk2UpLine = true;
bool isOkDnLine = true;
bool isOk2DnLine = true;

// ------------------------------------------------------------------------------------------|
// I N I T I A L I S A T I O N |
// ------------------------------------------------------------------------------------------|
//|------------------------------------------------------------------------------------------|
//| I N I T I A L I S A T I O N |
//|------------------------------------------------------------------------------------------|
int init()
{
InitInit();
Expand Down Expand Up @@ -95,10 +108,107 @@ int start()

//--- Assert there are NO opened trades.
int total=EasyOrdersBasket(Fred1Magic, Symbol());
if( total > 0 ) return(0);
EaDebugPrint( 2,"start",
EaDebugInt("total",total),
true, 0 );
if( total > 0 )
{
//--- Assert SmartExit means that EA will not check for exit condition (SL will be used instead).
if(!FredSmartExit) return(0);

if( EasyOrdersSellBasket(Fred1Magic, Symbol()) > 0 )
{
//--- Load global variables if it does not exist (default: exit condition fails)
gTDIsOkUpLineStr = StringConcatenate( Symbol(), "_", Period(), "_IsOkUpLine" );
gTDIsOk2UpLineStr = StringConcatenate( Symbol(), "_", Period(), "_IsOk2UpLine" );
isOkUpLine = GlobalVariableGet( gTDIsOkUpLineStr );
if( GetLastError()!=0 )
{
EaDebugPrint(0, "start",
EaDebugStr("EaName",EaName)+
EaDebugStr("EaVer",EaVer)+
EaDebugInt("mgc",Fred1Magic)+
EaDebugStr("sym",Symbol())+
EaDebugStr("gTDIsOkUpLineStr",gTDIsOkUpLineStr)+
EaDebugBln("isOkUpLine",isOkUpLine)+
" global var does not exist.",
false, 0);
isOkUpLine = true;
}
isOk2UpLine = GlobalVariableGet( gTDIsOk2UpLineStr );
if( GetLastError()!=0 )
{
EaDebugPrint(0, "start",
EaDebugStr("EaName",EaName)+
EaDebugStr("EaVer",EaVer)+
EaDebugInt("mgc",Fred1Magic)+
EaDebugStr("sym",Symbol())+
EaDebugStr("gTDIsOk2UpLineStr",gTDIsOk2UpLineStr)+
EaDebugBln("isOk2UpLine",isOk2UpLine)+
" global var does not exist.",
false, 0);
isOk2UpLine = true;
}
//--- Assert check exit condition for SELL basket
if( isOkUpLine == false && isOk2UpLine == false )
{
EasyBuyToCloseBasket( Fred1Magic, Symbol(), EasyMaxAccountTrades );
EaDebugPrint(0, "start",
EaDebugStr("EaName",EaName)+
EaDebugStr("EaVer",EaVer)+
EaDebugInt("mgc",Fred1Magic)+
EaDebugStr("sym",Symbol())+
" SmartExit closed ALL SELL basket.",
false, 0);
}
}
else if( EasyOrdersBuyBasket(Fred1Magic, Symbol()) > 0 )
{
//--- Load global variables if it does not exist (default: exit condition fails)
gTDIsOkDnLineStr = StringConcatenate( Symbol(), "_", Period(), "_IsOkDnLine" );
gTDIsOk2DnLineStr = StringConcatenate( Symbol(), "_", Period(), "_IsOk2DnLine" );
isOkDnLine = GlobalVariableGet( gTDIsOkDnLineStr );
if( GetLastError()!=0 )
{
EaDebugPrint(0, "start",
EaDebugStr("EaName",EaName)+
EaDebugStr("EaVer",EaVer)+
EaDebugInt("mgc",Fred1Magic)+
EaDebugStr("sym",Symbol())+
EaDebugStr("gTDIsOkDnLineStr",gTDIsOkDnLineStr)+
EaDebugBln("isOkDnLine",isOkDnLine)+
" global var does not exist.",
false, 0);
isOkDnLine = true;
}
isOk2DnLine = GlobalVariableGet( gTDIsOk2DnLineStr );
if( GetLastError()!=0 )
{
EaDebugPrint(0, "start",
EaDebugStr("EaName",EaName)+
EaDebugStr("EaVer",EaVer)+
EaDebugInt("mgc",Fred1Magic)+
EaDebugStr("sym",Symbol())+
EaDebugStr("gTDIsOk2DnLineStr",gTDIsOk2DnLineStr)+
EaDebugBln("isOk2DnLine",isOk2DnLine)+
" global var does not exist.",
false, 0);
isOk2DnLine = true;
}
//--- Assert check exit condition for BUY basket
if( isOkDnLine == false && isOk2DnLine == false )
{
EasySellToCloseBasket( Fred1Magic, Symbol(), EasyMaxAccountTrades );
EaDebugPrint(0, "start",
EaDebugStr("EaName",EaName)+
EaDebugStr("EaVer",EaVer)+
EaDebugInt("mgc",Fred1Magic)+
EaDebugStr("sym",Symbol())+
" SmartExit closed ALL BUY basket.",
false, 0);
}
}
//--- Assert if there are ANY trades opened, that means exit condition failed.
total=EasyOrdersBasket(Fred1Magic, Symbol());
if(total>0) return(0);
}

string gFredNewBarStr = StringConcatenate( Symbol(), "_", period, "_NewBar" );
bool newBar = GlobalVariableGet( gFredNewBarStr );
Expand Down Expand Up @@ -196,6 +306,8 @@ string EaComment(string cmt="")
strtmp = strtmp + " Do Not Trade Sell\n";
if( FredDoNotTrade<0 )
strtmp = strtmp + " Do Not Trade Buy\n";
if( FredSmartExit )
strtmp = strtmp + " SmartExit Enabled.\n";

//--- Assert additional comments here
strtmp=RedComment(strtmp);
Expand Down

0 comments on commit 0e81f23

Please sign in to comment.