Jump to content

ZACFIGHTER and LEOPARD SCALPER


Recommended Posts

  • Replies 143
  • Created
  • Last Reply

Top Posters In This Topic

Re: ZACFIGHTER and LEOPARD SCALPER

 

http://stashbox.org/589999/IM%20Scalper.zip

 

that's a demo version of IM-Scalper i fixed to run backtests/demo on (fixed time restriction).

 

all the variables seem to be internalised. and its a version from last year -- there might have been an update. but something to start with.

 

http://www.currencyscalper.com/html/exp ... isors.html that page might help people find the other EAs.

 

zacfighter EA demo account:

Broker Name: FXOpen

Login:704424

Investor: cy4wlqx

Server Demo

Link to comment
Share on other sites

Re: [Req] ZACFIGHTER and LEOPARD SCALPER

 

change the maximum allowed spread in the code, i.e. IMScalper:

 

look for this line of code

int gi_116 = 15;

 

and change it to

int gi_116 = 100;

 

both scalpers work only, if you have a spread of max. 1.5 pips. totally crap in my eyes 8-)

Link to comment
Share on other sites

Re: [Req] ZACFIGHTER and LEOPARD SCALPER

 

Hi guys,

 

I backtested it and it shows it is so great EA, but there is a problem with the money management. The MM goes really high then the account blow up because of that.

 

Can anyone indicate the MM code in the EA, please? I was trying to find it, but no luck.

 

Please let me know as soon as possible.

 

Best wishes,

Link to comment
Share on other sites

Re: [Req] ZACFIGHTER and LEOPARD SCALPER

 

yes. it always blows up. the only one i found that kept going was eurchf for the year to date.

 

there's a lot of features in the start of the code, but i do not know how to get the out and have them able to be played with to run tests.

 

i had the eurchf turns 9 times over the course of the year to date up to almost 100k from 10k. so i would like to play with the settings somewhat to see if it can be tamed.

Link to comment
Share on other sites

Re: [Req] ZACFIGHTER and LEOPARD SCALPER

 

Thanks Stormin for your reply.

 

I will keep digging to find the MM code and play with and maybe I can make it external feature instead of playing with the code every time. There is something interesting about this EA is that the way how it goes in chasing pips is so cool and maybe if we add a zigzag to that, it will be more powerful.

 

Best wishes,

Link to comment
Share on other sites

Re: [Req] ZACFIGHTER and LEOPARD SCALPER

 

The original code:

 

//+------------------------------------------------------------------+
//| Bless.FifthE.TK.2.0.2.mq4 |
//| Open source at Forex-TSD forum, [url]www.forex-tsd.com[/url] |
//| Ideas proposed by rifo.valas Bless System |
//| Coded by FiFtHeLeMeNt, [email][email protected][/email] |
//| Mofified by tkforextsd, [email][email protected][/email] |
//+------------------------------------------------------------------+
//
// History of FifthE's versions:
// Verion 1.0.0: bless_FiftHeLeMent_noTG_1.0.0.mq4
// Original FifthE version without MaxTrades
// Verion 1.0.1: bless_FiftHeLeMent_noTG_1.0.1.mq4
// FifthE version with MaxTrades
// Verion 1.0.3: bless_FiftHeLeMent_1.0.3.mq4
// FifthE version with spread control and LotInc
//
// History of TK's versions:
// Based on FifthE's bless_FiftHeLeMent_noTG_1.0.1.mq4
// Version 1.0.2: bless_FiftHeLeMent_noTG_1.0.2.mq4
// Add stoploss at MaxTrades level to protect capital
// Version 1.0.3: bless_FiftHeLeMent_noTG_1.0.3.mq4
// Add EA closing features: CloseImmediately, CloseOnTime,
// CloseOnFloatingLoss, CloseOnEquityTarget
// Version 1.0.4: bless_FiftHeLeMent_noTG_1.0.4.mq4
// Add selectable multiplier progression
// Add auto restart after equity target reach
// Add email alert when margin level low
// Add email alert when trade level reach a preset level
// Add more info in chart comments
//
// History of unified versions:
// Version 2.0: Bless.FifthE.TK.2.0.mq4
// Merge TK's bless_FiFtHeLeMeNt_noTG_1.0.4.mq4 and FifthE's bless_FiftHeLeMent_1.0.3.mq4
// Unified features: Selectable Multiplier, LotInc, Spread control, MaxTrades stop loss,
// x% equity restart, closing order management, email alert
// New features:
// Breakeven bail out after BEP_Level reach
// Opposite direction hedge at MaxTrades
//

#property copyright "Forex-tsd open source"
#property link "http://www.forex-tsd.com"

#include <stdlib.mqh>
#include <gMail.mqh>

extern string Expert_Name = "---- Bless.FifthE.TK.2.0.2.mq4 ----";
extern int MinGS = 20; //pips between each level
extern int TP = 27; //pips to take profit each trade
extern int SL = 140; //pips to stoploss each trade. Set to zero for no stoploss

extern double lot = 0.01; //starting lot size
extern bool AccountIsMini = true; // Set to true if trading mini account, otherwise set to false
extern int MaxTrades = 7; //max level allowed
extern int RegularSpread = 4; //max spread rejection, reject trades if spread exceed this value
extern double Multiplier = 2; //lots progressive multiplier factor
extern double LotInc = 0; //Lot increment on each level
extern int BEP_Level = 5; //breakeven bail out level

extern bool SetMaxTradesSL = true; //Set stop loss at Maxtrades level
extern bool SetMaxTradesHedge = false; //Set hedge trade at MaxTrades level

extern string Close_Management = "---- EA Closing Management ----";
extern bool CloseImmediately = false;

extern string s1 = "---- Close on time setting ----";
extern bool CloseOnTime = false;
extern int CloseHour = 23; //Time to close, Hour
extern int CloseMinute = 0; //Time to close, minutes

extern string s2 = "---- Close when floating profit/loss no more than MaxFloatPL settings ----";
extern bool CloseOnFloatPL = false;
extern double MaxFloatPL = 100.00; //Max floating profit/loss allowed when closing EA
extern double MinFloatPL = -100.00; //Min floating profit/loss allowed when closing EA

extern string s3 = "---- Close when equity hit target settings ----";
extern bool CloseOnEquityTarget = false;
extern bool AutoRestartAfterEqTarget = false;
extern double EquityTargetPercentage = 5.0; //Percentage equity growth when closing EA

extern string s4 = "---- Comment settings ----";
extern bool DisableComments = false; //turn off comments

extern string s5 = "---- Email settings ----";
extern bool TestEmail = false; //if true send a test email every 5 minutes
extern string EmailAddress = "[email protected]";
extern int EmailIteration = 3; //How namy times email send when alert active

extern string s6 = "---- Alert settings ----";
extern bool AlertOnLowMargin = false; //email alert when margin low
extern double MarginPercentage = 100.0; //margin low percentage
extern bool AlertOnTradeLevel = false; //email alert when trade level reach
extern int AlertTradeLevel = 6; //trade level to alert


int magic;
double lot2; //lots to open at each level
int LotDigits;
datetime tob,tos; //Time Out Buy & Sell
double SL_Point; //stoploss price at MaxTrades level
double TP_Point; //TP price at each level


bool Halt = false;
double StartBalance, EquityTarget;
double MarginPer;
int CurrentLevel = 0;
int BuyLevel, SellLevel;
int Slippage = 1;
bool HedgeBuy = false;
bool HedgeSell = false;


//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----



//----
return(0);
}

int init()
{
if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD") { magic = 211001; }
if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY") { magic = 211002; }
if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD") { magic = 211003; }
if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD") { magic = 211004; }
if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY") { magic = 211005; }
if (Symbol() == "EURAUDm" || Symbol() == "EURAUD") { magic = 211006; }
if (Symbol() == "EURCADm" || Symbol() == "EURCAD") { magic = 211007; }
if (Symbol() == "EURCHFm" || Symbol() == "EURCHF") { magic = 211008; }
if (Symbol() == "EURGBPm" || Symbol() == "EURGBP") { magic = 211009; }
if (Symbol() == "EURJPYm" || Symbol() == "EURJPY") { magic = 211010; }
if (Symbol() == "EURUSDm" || Symbol() == "EURUSD") { magic = 211011; }
if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF") { magic = 211012; }
if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY") { magic = 211013; }
if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD") { magic = 211014; }
if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY") { magic = 211015; }
if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD") { magic = 211016; }
if (Symbol() == "USDCHFm" || Symbol() == "USDCHF") { magic = 211017; }
if (Symbol() == "USDJPYm" || Symbol() == "USDJPY") { magic = 211018; }
if (Symbol() == "USDCADm" || Symbol() == "USDCAD") { magic = 211019; }
if (magic == 0) { magic = 211999; }

Halt = false;
LotDigits = 1;
if (AccountIsMini) { LotDigits = 2; }
HedgeBuy = false;
HedgeSell = false;
return(0);
}

void OpenBuy()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", TimeCurrent()); // set lock indicator
ticket = OrderSend(Symbol(),OP_BUY,lot2,Ask,Slippage,SL_Point,TP_Point,"EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}

void OpenSell()
{
int ticket,err;
if (!GlobalVariableCheck("InTrade")) {
GlobalVariableSet("InTrade", TimeCurrent()); // set lock indicator
ticket = OrderSend(Symbol(),OP_SELL,lot2,Bid,Slippage,SL_Point,TP_Point,"EA Order",magic,0,Red);
GlobalVariableDel("InTrade"); // clear lock indicator
}
}


void ManageBuy()
{
int lasttradetime = 0;
double lastopenprice=0;
double maxlots = 0;
double lasttp=0;
double lastsl=0;
int lastordertype=-1;
int lastorderticket=0;
int y=0;

//BuyLevel = 0;
for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY)) { continue; }
if (OrderOpenTime() >= lasttradetime) {
lasttradetime = OrderOpenTime();
lastopenprice = OrderOpenPrice();
lastordertype=OrderType();
lastorderticket=OrderTicket();
lasttp=OrderTakeProfit();
lastsl=OrderStopLoss();
}
if (OrderLots() > maxlots) { maxlots = OrderLots(); }
//BuyLevel++;
}

BuyLevel = MathRound(MathLog((maxlots-LotInc)/lot)/MathLog(Multiplier)+1);
lot2 = NormalizeDouble(lot*MathPow(Multiplier, BuyLevel)+LotInc, LotDigits);

if( SL > 0 ) SL_Point = Ask - SL*Point;
else SL_Point = 0;

TP_Point = Ask + TP*Point;

if ((BuyLevel==0) && (((Ask-Bid)/Point)<=RegularSpread) && !Halt ) {
OpenBuy();
BuyLevel++;
CurrentLevel=BuyLevel;
return(0);
}

if ((lastopenprice-Ask>MinGS*Point) && (BuyLevel==MaxTrades-1) && (SetMaxTradesSL || SetMaxTradesHedge) ) {
//set stoploss at the last open level
SL_Point = Ask - MinGS*Point;
}

if ((lastopenprice-Ask>MinGS*Point) && (BuyLevel<MaxTrades) && (((Ask-Bid)/Point)<=RegularSpread) && !Halt && !HedgeBuy ) {
OpenBuy();
BuyLevel++;
CurrentLevel=BuyLevel;
return(0);
}

CurrentLevel=BuyLevel;

/////////// TP
/*
double sumlots=0;
double sump=0;
double avgp=0;
for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY)) { continue; }
sumlots=sumlots+OrderLots();
sump=OrderOpenPrice()*OrderLots()+sump;
}

if (sumlots>0) {
avgp=NormalizeDouble(sump/sumlots,Digits);
double tpp=NormalizeDouble(TP/10/sumlots*Point+avgp,Digits);

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY) || (OrderTakeProfit()==tpp)) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tpp,0,Red);
}


}
*/

for (y = OrdersTotal()-1; y >= 0; y--)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_BUY) || (OrderTakeProfit()==lasttp) || (lasttp==0) || HedgeBuy ) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),lasttp,0,Red);
}

//reverse hedge
if (BuyLevel==MaxTrades && !HedgeSell && SetMaxTradesHedge) {
TP_Point = lastsl;
SL_Point = lasttp;
OpenSell();
HedgeSell = true;
return(0);
}

}

void ManageSell()
{
int lasttradetime = 0;
double lastopenprice=0;
double maxlots = 0;
double lasttp=0;
double lastsl=0;
int lastordertype=-1;
int lastorderticket=0;
int y=0;

//SellLevel = 0;
for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL)) { continue; }
if (OrderOpenTime() >= lasttradetime) {
lasttradetime = OrderOpenTime();
lastopenprice = OrderOpenPrice();
lastordertype=OrderType();
lastorderticket=OrderTicket();
lasttp=OrderTakeProfit();
lastsl=OrderStopLoss();
}
if (OrderLots() > maxlots) { maxlots = OrderLots(); }
//SellLevel++;
}

SellLevel = MathRound(MathLog((maxlots-LotInc)/lot)/MathLog(Multiplier)+1);
lot2 = NormalizeDouble(lot*MathPow(Multiplier, SellLevel)+LotInc, LotDigits);

if( SL > 0 ) SL_Point = Bid + SL*Point;
else SL_Point = 0;

TP_Point = Bid-TP*Point;

if ((SellLevel==0) && (((Ask-Bid)/Point)<=RegularSpread) && !Halt ) {
OpenSell();
SellLevel++;
if (SellLevel>CurrentLevel) CurrentLevel=SellLevel;
return(0);
}

if ((Bid-lastopenprice>MinGS*Point) && (SellLevel==MaxTrades-1) && (SetMaxTradesSL || SetMaxTradesHedge) ) {
//set stoploss at the last open level
SL_Point = Bid + MinGS*Point;
}

if ((Bid-lastopenprice>MinGS*Point) && (lastopenprice>0) && (SellLevel<MaxTrades) && (((Ask-Bid)/Point)<=RegularSpread) && !Halt && !HedgeSell ) {
OpenSell();
SellLevel++;
if (SellLevel>CurrentLevel) CurrentLevel=SellLevel;
return(0);
}
if (SellLevel>CurrentLevel) CurrentLevel=SellLevel;

/////////// TP
/* double sumlots=0;
double sump=0;
double avgp=0;
for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL)) { continue; }
sumlots=sumlots+OrderLots();
sump=OrderOpenPrice()*OrderLots()+sump;
}

if (sumlots>0) {
avgp=NormalizeDouble(sump/sumlots,Digits);
double tpp=NormalizeDouble(-TP/10/sumlots*Point+avgp,Digits);

for (y = 0; y < OrdersTotal(); y++)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL) || (OrderTakeProfit()==tpp)) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),tpp,0,Red);
}


}
*/

for (y = OrdersTotal()-1; y >= 0; y--)
{
OrderSelect (y, SELECT_BY_POS, MODE_TRADES);
if ((OrderMagicNumber() != magic) || (OrderType()!=OP_SELL) || (OrderTakeProfit()==lasttp) || (lasttp==0) || HedgeSell || HedgeSell ) { continue; }
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),lasttp,0,Red);
}

//reverse hedge
if (SellLevel==MaxTrades && !HedgeBuy && SetMaxTradesHedge) {
TP_Point = lastsl;
SL_Point = lasttp;
OpenBuy();
HedgeBuy = true;
return(0);
}

}


//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

ManageClose();

ManageBuy();

ManageSell();

if(!IsTesting()) HandleAlerts();

if(!IsTesting()) ChartComment();

//----
return(0);
}
//+------------------------------------------------------------------+


void CloseAllTrades()
{
int total = OrdersTotal();
for (int y=OrdersTotal()-1; y>=0; y--)
{
OrderSelect(y, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber() == magic)
{
int type = OrderType();
bool result = false;
int TriesNum = 5;
int tries=0;
while (!result && tries < TriesNum)
{
RefreshRates();
switch(type)
{
case OP_BUY :
result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Pink);
break;
case OP_SELL:
result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);
}
tries++;
}
if (!result) Print("Error closing order : ",ErrorDescription(GetLastError()));
}
}
}


bool LastCloseOnEquityTarget = false;

void ManageClose()
{
//Breakeven bail out after BEP_Level
if ((CurrentLevel>=BEP_Level) && (AccountProfit()>=0)) {
CloseAllTrades();
}

//Reverse hedge at Maxtrades level
if ((BuyLevel<MaxTrades) && HedgeSell) { HedgeSell = false; }
if ((SellLevel<MaxTrades) && HedgeBuy) { HedgeBuy = false; }

if (CloseOnEquityTarget && !LastCloseOnEquityTarget) {
StartBalance = AccountBalance();
}
LastCloseOnEquityTarget = CloseOnEquityTarget;

if (CloseImmediately)
{
CloseAllTrades();
Halt = true;
}
if (CloseOnTime && Hour()==CloseHour && Minute()>=CloseMinute)
{
CloseAllTrades();
Halt = true;
}
if (CloseOnFloatPL && (AccountProfit()>=MaxFloatPL || AccountProfit()<=MinFloatPL) )
{
CloseAllTrades();
Halt = true;
}
if (CloseOnEquityTarget && !Halt)
{
EquityTarget = StartBalance*(1.0 + EquityTargetPercentage/100.0);
if (AccountEquity()>=EquityTarget )
{
CloseAllTrades();
StartBalance = AccountBalance();
if (!AutoRestartAfterEqTarget) Halt = true;
}
}
if (!CloseImmediately && !CloseOnTime && !CloseOnFloatPL && !CloseOnEquityTarget )
{
if (Halt) StartBalance = AccountBalance();
Halt = false;
}

}


void ChartComment()
{
string sComment = "";
string sp = "----------------------------------------\n";
string Activity = "-----------Trading Activity-------------\n";
string CloseManage = "-----------Closing Management-----------\n";
string AcctStatus = "-----------Account Status---------------\n";
string NL = "\n";

double spread = MarketInfo(Symbol(),MODE_SPREAD);
double SwapLong = MarketInfo(Symbol(),MODE_SWAPLONG);
double SwapShort = MarketInfo(Symbol(),MODE_SWAPSHORT);


sComment = Activity;
sComment = sComment + "Current time is " + TimeToStr(TimeCurrent()) + NL;
if (Halt)
sComment = sComment + "Trading halt!!! To resume trading set ALL closing conditions to FALSE." + NL;
else
sComment = sComment + "Trading is active at level " + CurrentLevel + NL;

if (CloseImmediately || CloseOnTime || CloseOnFloatPL || CloseOnEquityTarget)
{
sComment = sComment + CloseManage;
if (CloseImmediately)
sComment = sComment + "Close Immediately!!!!" + NL;
if (CloseOnTime)
sComment = sComment + "Close on time is active when " + CloseHour + ":" + CloseMinute + NL;
if (CloseOnFloatPL)
sComment = sComment + "Close on floating loss is active when float P/L >= " + DoubleToStr(MaxFloatPL,2) + NL;
if (CloseOnEquityTarget)
sComment = sComment + "Close on equity target is active when EquityTarget >= " + DoubleToStr(EquityTarget,2) + NL;
}

sComment = sComment + AcctStatus;
sComment = sComment + "Balance: " + DoubleToStr(AccountBalance(), 2) + ", Equity: " + DoubleToStr(AccountEquity(),2)
+ ", Leverage: " + DoubleToStr(AccountLeverage(),2) + ", Lots: " + DoubleToStr(lot2,2) + NL;
sComment = sComment + "MinGS: " + MinGS + ", TP: " + TP + ", Buy Level: " + BuyLevel + ", Sell Level: " + SellLevel + ", MaxTrades: " + MaxTrades + NL;

sComment = sComment + "Spread: " + DoubleToStr(spread,1) + ", SWAP Long: " + DoubleToStr(SwapLong,2) + ", SWAP Short: " + DoubleToStr(SwapShort,2) + NL;

sComment = sComment + "AccountMargin: " + DoubleToStr(AccountMargin(), 2) + ", Margin%: " + DoubleToStr(MarginPer,2) + "%" + NL;
sComment = sComment + sp;

if (!DisableComments) Comment(sComment);
else Comment("");

}

//Alert handling variables
bool LastTestEmail = false;
int TestEmailCnt = 0;
bool LastAlertOnLowMargin = false;
int AlertOnLowMarginCnt = 0;
bool LastAlertOnTradeLevel = false;
int AlertOnTradeLevelCnt = 0;
bool TimeToSend;
datetime LastTime;


void HandleAlerts()
{
string Message = "";

//RefreshRates();
//Switch on detection
if (TestEmail && !LastTestEmail) {
TestEmailCnt = EmailIteration;
LastTime = TimeCurrent();
}
if (AlertOnLowMargin && !LastAlertOnLowMargin) {
AlertOnLowMarginCnt = EmailIteration;
LastTime = TimeCurrent();
}
if (AlertOnTradeLevel && !LastAlertOnTradeLevel) {
AlertOnTradeLevelCnt = EmailIteration;
LastTime = TimeCurrent();
}

//Update
LastTestEmail = TestEmail;
LastAlertOnLowMargin = AlertOnLowMargin;
LastAlertOnTradeLevel = AlertOnTradeLevel;

//Handle email alert
if (TimeCurrent() - LastTime >= 300) { TimeToSend = true; }
else { TimeToSend = false; }

if (TestEmail && TimeToSend && TestEmailCnt>0 && MathMod(TestEmailCnt,2)==0) {
Message = "Go ahead! Make my day! -- Dirty Harry\r\n";
Message = Message + "A courtersy message from your best EA\r\n";
Message = Message + "Brought to you by FiFtHElEMeNt and tkforextsd\r\n";
Message = Message + "Regards\r\nHappy trading!\r\n";
gSendMail("default", EmailAddress, "Bless EA test email", Message, "", "");
TestEmailCnt--;
LastTime = TimeCurrent();
}
if (TestEmail && TimeToSend && TestEmailCnt>0 && MathMod(TestEmailCnt,2)==1) {
Message = "I\'ll be back! -- Terminator\r\n";
Message = Message + "A courtersy message from your best EA\r\n";
Message = Message + "Brought to you by FiFtHElEMeNt and tkforextsd\r\n";
Message = Message + "Regards\r\nHappy trading!\r\n";
gSendMail("default", EmailAddress, "Bless EA test email", Message, "", "");
TestEmailCnt--;
LastTime = TimeCurrent();
}

if (AccountMargin()==0) MarginPer = 100000;
else MarginPer = AccountEquity()/AccountMargin()*100.0;
if (AlertOnLowMargin && (MarginPer<=MarginPercentage) && TimeToSend && (AlertOnLowMarginCnt>0) ) {
Message = "Margin% low alert\r\n";
Message = Message + "Symbol: " + Symbol() + ", Margin%: " + DoubleToStr(MarginPer,2) + "%\r\n";
gSendMail("default", EmailAddress, "Bless EA margin% low alert", Message, "", "");
AlertOnLowMarginCnt--;
LastTime = TimeCurrent();
}

if (AlertOnTradeLevel && (CurrentLevel>=AlertTradeLevel) && TimeToSend && (AlertOnTradeLevelCnt>0) ) {
Message = "Trade level alert\r\n";
Message = Message + "Symbol: " + Symbol() + ", trade level: " + CurrentLevel + " reach!\r\n";
gSendMail("default", EmailAddress, "Bless EA trade level alert", Message, "", "");
AlertOnTradeLevelCnt--;
LastTime = TimeCurrent();
}

}


Link to comment
Share on other sites

Re: [Req] ZACFIGHTER and LEOPARD SCALPER

 

With renamed variables:

 

#property copyright "Copyright © 2007, Imran Expert"
#property link      "http://www.currencyscalper.com"

#include <stdlib.mqh>

string gs_unused_76 = "---- ImranExpert.mq4 ----";
int MinGS = 20;
int TP = 27;
double gd_100;
int SL = 150;
int MaxTrades = 8;
int RegularSpread = 15;
double gd_120 = 2.0;
double gd_128 = 0.0;
int gi_136 = 10;
bool gi_148 = FALSE;
string gs_unused_152 = "---- EA Closing Management ----";
bool CloseImmediately = FALSE;
string gs_unused_164 = "---- Close on time setting ----";
bool CloseOnTime = FALSE;
int CloseHour = 24;
int CloseMinute = 0;
string gs_unused_184 = "---- Close when floating profit/loss no more than MaxFloatPL settings ----";
bool CloseOnFloatPL = FALSE;
double MaxFloatPL = -2500.0;
string gs_unused_204 = "---- Close when equity hit target settings ----";
bool CloseOnEquityTarget = FALSE;
bool AutoRestartAfterEqTarget = TRUE;
double EquityTargetPercentage = 1.0;
int gi_228;
int MagicNo;
double lot2;
int LotDigits;
double SL_Point;
double TP_Point;
bool Halt = FALSE;
double EquityTarget;
int CurrentLevel = 0;
int BuyLevel;
int SellLevel;
int Slippage = 1;
int g_count_348 = 0;
int g_count_352 = 0;
bool gi_356 = FALSE;
bool gi_360 = FALSE;
bool LastCloseOnEquityTarget = FALSE;

int deinit() {
  return (0);
}

int init() {
  if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD") MagicNo = 211001;
  if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY") MagicNo = 211002;
  if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD") MagicNo = 211003;
  if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD") MagicNo = 211004;
  if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY") MagicNo = 211005;
  if (Symbol() == "EURAUDm" || Symbol() == "EURAUD") MagicNo = 211006;
  if (Symbol() == "EURCADm" || Symbol() == "EURCAD") MagicNo = 211007;
  if (Symbol() == "EURCHFm" || Symbol() == "EURCHF") MagicNo = 211008;
  if (Symbol() == "EURGBPm" || Symbol() == "EURGBP") MagicNo = 211009;
  if (Symbol() == "EURJPYm" || Symbol() == "EURJPY") MagicNo = 211010;
  if (Symbol() == "EURUSDm" || Symbol() == "EURUSD") MagicNo = 211011;
  if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF") MagicNo = 211012;
  if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY") MagicNo = 211013;
  if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD") MagicNo = 211014;
  if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY") MagicNo = 211015;
  if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD") MagicNo = 211016;
  if (Symbol() == "USDCHFm" || Symbol() == "USDCHF") MagicNo = 211017;
  if (Symbol() == "USDJPYm" || Symbol() == "USDJPY") MagicNo = 211018;
  if (Symbol() == "USDCADm" || Symbol() == "USDCAD") MagicNo = 211019;
  if (MagicNo == 0) MagicNo = 211999;
  Halt = FALSE;
  LotDigits = 2;
  return (0);
}

void OpenBuy() {
  int l_ticket_0;
  if (!GlobalVariableCheck("InTrade")) {
     GlobalVariableSet("InTrade", TimeCurrent());
     l_ticket_0 = OrderSend(Symbol(), OP_BUY, lot2, Ask, Slippage, SL_Point, TP_Point, "EA Order", MagicNo, 0, Red);
     GlobalVariableDel("InTrade");
  }
}

void OpenSell() {
  int l_ticket_0;
  if (!GlobalVariableCheck("InTrade")) {
     GlobalVariableSet("InTrade", TimeCurrent());
     l_ticket_0 = OrderSend(Symbol(), OP_SELL, lot2, Bid, Slippage, SL_Point, TP_Point, "EA Order", MagicNo, 0, Red);
     GlobalVariableDel("InTrade");
  }
}

void ManageBuy() {
  if (EquityTargetPercentage > 20.0) EquityTargetPercentage = 20;
  int lasttradetime = 0;
  double lastopenprice = 0;
  double maxlots = 0;
  double lasttp = 0;
  double lastsl = 0;
  int lastordertype = -1;
  int lastorderticket = 0;
  int l_pos_44 = 0;
  gi_228 = 400000 / EquityTargetPercentage;
  gd_100 = AccountEquity() / gi_228;
  BuyLevel = 0;
  for (l_pos_44 = 0; l_pos_44 < OrdersTotal(); l_pos_44++) {
     OrderSelect(l_pos_44, SELECT_BY_POS, MODE_TRADES);
     if (OrderMagicNumber() != MagicNo || OrderType() != OP_BUY) continue;
     if (OrderOpenTime() >= lasttradetime) {
        lasttradetime = OrderOpenTime();
        lastopenprice = OrderOpenPrice();
        lastordertype = OrderType();
        lastorderticket = OrderTicket();
        lasttp = OrderTakeProfit();
        lastsl = OrderStopLoss();
     }
     if (OrderLots() > maxlots) maxlots = OrderLots();
     BuyLevel++;
  }
  lot2 = NormalizeDouble(gd_100 * MathPow(gd_120, BuyLevel) + gd_128, LotDigits);
  double l_icustom_48 = iCustom(NULL, 0, "MACDTraditional", 12, 20, 9, 2, 0);
  double l_icustom_56 = iCustom(NULL, 0, "Laguerre-ACS1", 0.6, 1000, 2, 0, 0);
  double l_icustom_64 = iCustom(NULL, 0, "Laguerre-ACS1", 0.8, 1000, 2, 0, 0);
  double l_icustom_72 = iCustom(NULL, 0, "StochHistogram", "First Stochastic", 14, 3, 3, 2, 0);
  int l_ind_counted_80 = IndicatorCounted();
  SL_Point = Bid - SL * Point;
  TP_Point = Ask + TP * Point;
  if (BuyLevel == 0 && (Ask - Bid) / Point <= RegularSpread && !Halt && l_icustom_48 > 0.0 && l_icustom_56 > l_icustom_64 && l_icustom_72 > 0.0) {
     gi_356 = TRUE;
     gi_148 = FALSE;
  }
  if (BuyLevel == 0 && (Ask - Bid) / Point <= RegularSpread && !Halt && gi_356 == TRUE && !gi_148 && l_icustom_48 > 0.0 && l_icustom_56 > l_icustom_64 && l_icustom_72 > 0.0) {
     OpenBuy();
     BuyLevel++;
     CurrentLevel = BuyLevel;
     gi_356 = TRUE;
     g_count_348++;
     return;
  }
  if (lastopenprice - Ask > MinGS * Point && BuyLevel < MaxTrades && (Ask - Bid) / Point <= RegularSpread && !Halt && gi_356) {
     OpenBuy();
     BuyLevel++;
     CurrentLevel = BuyLevel;
     return;
  }
  for (l_pos_44 = OrdersTotal() - 1; l_pos_44 >= 0; l_pos_44--) {
     OrderSelect(l_pos_44, SELECT_BY_POS, MODE_TRADES);
     if (OrderMagicNumber() != MagicNo || OrderType() != OP_BUY || OrderTakeProfit() == lasttp || lasttp == 0.0) continue;
     OrderModify(OrderTicket(), OrderOpenPrice(), lastsl, lasttp, 0, Red);
  }
}

void ManageSell() {
  if (EquityTargetPercentage > 20.0) EquityTargetPercentage = 20;
  int lasttradetime = 0;
  double lastopenprice = 0;
  double maxlots = 0;
  double lasttp = 0;
  double lastsl = 0;
  int lastordertype = -1;
  int lastorderticket = 0;
  int l_pos_44 = 0;
  gi_228 = 400000 / EquityTargetPercentage;
  gd_100 = AccountEquity() / gi_228;
  SellLevel = 0;
  for (l_pos_44 = 0; l_pos_44 < OrdersTotal(); l_pos_44++) {
     OrderSelect(l_pos_44, SELECT_BY_POS, MODE_TRADES);
     if (OrderMagicNumber() != MagicNo || OrderType() != OP_SELL) continue;
     if (OrderOpenTime() >= lasttradetime) {
        lasttradetime = OrderOpenTime();
        lastopenprice = OrderOpenPrice();
        lastordertype = OrderType();
        lastorderticket = OrderTicket();
        lasttp = OrderTakeProfit();
        lastsl = OrderStopLoss();
     }
     if (OrderLots() > maxlots) maxlots = OrderLots();
     SellLevel++;
  }
  lot2 = NormalizeDouble(gd_100 * MathPow(gd_120, SellLevel) + gd_128, LotDigits);
  double l_icustom_48 = iCustom(NULL, 0, "MACDTraditional", 12, 20, 9, 2, 0);
  double l_icustom_56 = iCustom(NULL, 0, "Laguerre-ACS1", 0.6, 1000, 2, 0, 0);
  double l_icustom_64 = iCustom(NULL, 0, "Laguerre-ACS1", 0.8, 1000, 2, 0, 0);
  double l_icustom_72 = iCustom(NULL, 0, "StochHistogram", "First Stochastic", 14, 3, 3, 2, 0);
  int l_ind_counted_80 = IndicatorCounted();
  SL_Point = Ask + SL * Point;
  TP_Point = Bid - TP * Point;
  if (SellLevel == 0 && (Ask - Bid) / Point <= RegularSpread && !Halt && l_icustom_48 < 0.0 && l_icustom_56 < l_icustom_64 && l_icustom_72 < 0.0) {
     gi_360 = TRUE;
     gi_148 = FALSE;
  }
  if (SellLevel == 0 && (Ask - Bid) / Point <= RegularSpread && !Halt && gi_360 == TRUE && !gi_148 && l_icustom_48 < 0.0 && l_icustom_56 < l_icustom_64 && l_icustom_72 < 0.0) {
     OpenSell();
     SellLevel++;
     if (SellLevel > CurrentLevel) CurrentLevel = SellLevel;
     gi_360 = TRUE;
     g_count_352++;
     return;
  }
  if (Bid - lastopenprice > MinGS * Point && lastopenprice > 0.0 && SellLevel < MaxTrades && (Ask - Bid) / Point <= RegularSpread && !Halt) {
     OpenSell();
     SellLevel++;
     if (SellLevel <= CurrentLevel) return;
     CurrentLevel = SellLevel;
     return;
  }
  for (l_pos_44 = OrdersTotal() - 1; l_pos_44 >= 0; l_pos_44--) {
     OrderSelect(l_pos_44, SELECT_BY_POS, MODE_TRADES);
     if (OrderMagicNumber() != MagicNo || OrderType() != OP_SELL || OrderTakeProfit() == lasttp || lasttp == 0.0) continue;
     OrderModify(OrderTicket(), OrderOpenPrice(), lastsl, lasttp, 0, Red);
  }
}

int start() {
  ManageClose();
  ManageBuy();
  ManageSell();
  return (0);
}

void CloseAllTrades() {
  int l_cmd_8;
  bool l_ord_close_12;
  int li_16;
  g_count_348 = 0;
  g_count_352 = 0;
  for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
     OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
     if (OrderMagicNumber() == MagicNo) {
        l_cmd_8 = OrderType();
        l_ord_close_12 = FALSE;
        li_16 = 5;
        for (int l_count_20 = 0; !l_ord_close_12 && l_count_20 < li_16; l_count_20++) {
           RefreshRates();
           switch (l_cmd_8) {
           case OP_BUY:
              l_ord_close_12 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage, Blue);
              break;
           case OP_SELL:
              l_ord_close_12 = OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage, Pink);
           }
        }
        if (!l_ord_close_12) Print("Error closing order : ", ErrorDescription(GetLastError()));
     }
  }
}

void ManageClose() {
  if (EquityTargetPercentage > 50.0) EquityTargetPercentage = 50;
  if (CurrentLevel >= gi_136 && AccountProfit() >= 0.0) CloseAllTrades();
  LastCloseOnEquityTarget = CloseOnEquityTarget;
  if (CloseImmediately) {
     CloseAllTrades();
     Halt = FALSE;
  }
  if (CloseOnTime && Hour() == CloseHour && Minute() >= CloseMinute && !Halt) {
     CloseAllTrades();
     Halt = FALSE;
  }
  if (CloseOnFloatPL && AccountProfit() >= MaxFloatPL) {
     CloseAllTrades();
     Halt = TRUE;
  }
  if (CloseOnEquityTarget && !Halt) {
     EquityTarget = AccountBalance() * (1.0 - EquityTargetPercentage / 100.0);
     if (AccountEquity() <= EquityTarget) {
        CloseAllTrades();
        if (!AutoRestartAfterEqTarget) Halt = TRUE;
     }
  }
  if (!CloseImmediately && !CloseOnTime && !CloseOnFloatPL && !CloseOnEquityTarget) {
     Halt = FALSE;
  }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...