hello fellow FF members and colleagues. i have been trading for 4 years and this is the best EA strategy i have come up with.
the keys are the fibo MA, its slope, and of course, the mighty smTRIX. oh yeah and price action!
however i am having trouble telling the EA how to initiate trades. i think the problem is the Trix values, even though the histogram appears to change colour, its value is often 0.
i would like the EA to enter buy orders on the vertical lines on the chart. so there needs to be a bullish candle of at least 3 pips and the current Trix bar needs to be greater than 0 and either of the previous 3 Trix values needs to be MediumSpringGreen.
please have a look at the code and the attachment and you should understand what i mean (i hope!).
i'm really not sure what i'm doing wrong.
anyways thanks very very much for any help
the keys are the fibo MA, its slope, and of course, the mighty smTRIX. oh yeah and price action!
however i am having trouble telling the EA how to initiate trades. i think the problem is the Trix values, even though the histogram appears to change colour, its value is often 0.
i would like the EA to enter buy orders on the vertical lines on the chart. so there needs to be a bullish candle of at least 3 pips and the current Trix bar needs to be greater than 0 and either of the previous 3 Trix values needs to be MediumSpringGreen.
please have a look at the code and the attachment and you should understand what i mean (i hope!).
i'm really not sure what i'm doing wrong.
anyways thanks very very much for any help
Inserted Code
#include <stdlib.mqh>
extern int myMagic = 1;
extern double TakeProfit =60;
extern bool PartialClosing = false;
extern int TPDivide = 1;
extern double StopLoss =15;
extern int TrailingStop =0;
extern double BreakEvenStop =20;
extern int slippage=3;
extern int shift=0;
extern double Lots = 0.01;
extern double MaximumRisk = 1.0; //
extern bool FixedLot = false;
extern int TimeStart1=0000;
extern int TimeStop1=2359;
extern int TimeStart2=0000;
extern int TimeStop2=0000;
extern int TimeStart3=0000;
extern int TimeStop3=0000;
extern int TimeStart4=0000;
extern int TimeStop4=0000;
extern int OrderTriesNumber=25;
bool buysig,sellsig,closebuy,closesell; int lastsig,tries;
double LotsRisk(int StopLoss) {
double lot=Lots;
//---- select lot size
if (!FixedLot && (StopLoss > 0))
lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk*0.001/StopLoss,2);
else
lot=Lots;
//---- return lot size
if(lot<0.01) lot=0.01;
return(lot);
}
//+------------------------------------------------------------------+
//| Calculate open positions |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
{
int buys=0,sells=0;
//----
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==myMagic)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
}
//---- return orders volume
if(buys>0) return(buys);
else return(-sells);
}
//+------------------------------------------------------------------+
//| Check for open order conditions |
//+------------------------------------------------------------------+
void CheckForSignals(datetime tradeopenbar) {
double iMA144=iMA(NULL,0,144,0,MODE_LWMA,PRICE_CLOSE,0);
double iMA987=iMA(NULL,0,987,0,MODE_SMA,PRICE_CLOSE,0);
double iMA55=iMA(NULL,0,55,0,MODE_EMA,PRICE_CLOSE,0);
double iMA13current=iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,0);
double iMA13previous=iMA(NULL,0,13,0,MODE_EMA,PRICE_CLOSE,+1);
double CCICurrent=iCCI(NULL,0,3,PRICE_CLOSE,0);
double CCIPrevious=iCCI(NULL,0,3,PRICE_CLOSE,+1);
double CycleCurrent2=iStochastic(NULL,0,3,2,2,MODE_SMA,0,MODE_MAIN,0); //MODE_SIGNAL is longer look back period
double CyclePrevious2=iStochastic(NULL,0,3,2,2,MODE_SMA,0,MODE_MAIN,+1); //MODE_MAIN is shorter look back period
double SAR001previous=iSAR(NULL,0,0.001,0.01,+1);
double SAR001current=iSAR(NULL,0,0.001,0.01,0);
double SAR0009previous=iSAR(NULL,0,0.0009,0.009,+1);
double SAR0009current=iSAR(NULL,0,0.0009,0.009,0);
double SAR0015previous=iSAR(NULL,0,0.0015,0.015,+1);
double SAR0015current=iSAR(NULL,0,0.0015,0.015,0);
double SAR0025previous=iSAR(NULL,0,0.0025,0.025,+1);
double SAR0025current=iSAR(NULL,0,0.0025,0.025,0);
double SAR0040previous=iSAR(NULL,0,0.0040,0.04,+1);
double SAR0040current=iSAR(NULL,0,0.0040,0.04,0);
double SAR0066previous=iSAR(NULL,0,0.0066,0.066,+1);
double SAR0066current=iSAR(NULL,0,0.0066,0.066,0);
double SAR02previous=iSAR(NULL,0,0.02,0.2,+1);
double SAR02current=iSAR(NULL,0,0.02,0.2,0);
double PrimeTimeUp=iCustom(NULL,0,"PrimeTime",23,1,0);
double PrimeTimeDown=iCustom(NULL,0,"PrimeTime",23,2,0);
double iZeroAlphaUp=iCustom(NULL,0,"iZeroAlpha",144,0.3,6,0,0,0);
double iZeroAlphaDown=iCustom(NULL,0,"iZeroAlpha",144,0.3,6,0,1,0);
double iZeroAlphaUp5=iCustom(NULL,0,"iZeroAlpha",144,0.3,6,0,0,5);
double iZeroAlphaDown5=iCustom(NULL,0,"iZeroAlpha",144,0.3,6,0,1,5);
double OpenPrice=iOpen(NULL,PERIOD_D1,0);
double TrendMagicUp=iCustom(NULL,0,"Trend Magic",50,5,0,0);
double TrendMagicDown=iCustom(NULL,0,"Trend Magic",50,5,1,0);
double HeikenAshiDownCurrent=iCustom(NULL,0,"Heiken Ashi_SWAlert",0,0,0);
double HeikenAshiUpCurrent=iCustom(NULL,0,"Heiken Ashi_SWAlert",0,1,0);
double HeikenAshiDownPrevious=iCustom(NULL,0,"Heiken Ashi_SWAlert",0,0,1);
double HeikenAshiUpPrevious=iCustom(NULL,0,"Heiken Ashi_SWAlert",0,1,1);
double smTRIXup=iCustom(NULL,0,"smTRIX",3,0,1,0);
double smTRIXdown=iCustom(NULL,0,"smTRIX",3,0,2,0);
double smTRIXupPrevious=iCustom(NULL,0,"smTRIX",3,0,1,1);
double smTRIXdownPrevious=iCustom(NULL,0,"smTRIX",3,0,2,1);
double smTRIXupPrevious2=iCustom(NULL,0,"smTRIX",3,0,1,2);
double smTRIXdownPrevious2=iCustom(NULL,0,"smTRIX",3,0,2,2);
double smTRIXupPrevious3=iCustom(NULL,0,"smTRIX",3,0,1,3);
double smTRIXdownPrevious3=iCustom(NULL,0,"smTRIX",3,0,2,3);
double smTRIXupPrevious6=iCustom(NULL,0,"smTRIX",3,0,1,6);
double smTRIXdownPrevious6=iCustom(NULL,0,"smTRIX",3,0,2,6);
double smTRIXupPrevious7=iCustom(NULL,0,"smTRIX",3,0,1,7);
double smTRIXdownPrevious7=iCustom(NULL,0,"smTRIX",3,0,2,7);
double smTRIXupPrevious8=iCustom(NULL,0,"smTRIX",3,0,1,8);
double smTRIXdownPrevious8=iCustom(NULL,0,"smTRIX",3,0,2,8);
double smTRIXupPrevious9=iCustom(NULL,0,"smTRIX",3,0,1,9);
double smTRIXdownPrevious9=iCustom(NULL,0,"smTRIX",3,0,2,9);
double smTRIXupPrevious10=iCustom(NULL,0,"smTRIX",3,0,1,10);
double smTRIXdownPrevious10=iCustom(NULL,0,"smTRIX",3,0,2,10);
// double iZeroSMAUp=iCustom(NULL,0,"iZeroSMA233",233,0.4,6,0,0,0);
// double iZeroSMADown=iCustom(NULL,0,"iZeroSMA233",233,0.4,6,0,1,0);
iMA144=NormalizeDouble(iMA144,Digits);
iMA987=NormalizeDouble(iMA987,Digits);
iMA55=NormalizeDouble(iMA55,Digits);
iMA13current=NormalizeDouble(iMA13current,Digits);
iMA13previous=NormalizeDouble(iMA13previous,Digits);
CCICurrent=NormalizeDouble(CCICurrent,Digits);
CCIPrevious=NormalizeDouble(CCIPrevious,Digits);
CycleCurrent2=NormalizeDouble(CycleCurrent2,Digits);
CyclePrevious2=NormalizeDouble(CyclePrevious2,Digits);
SAR001previous=NormalizeDouble(SAR001previous,Digits);
SAR001current=NormalizeDouble(SAR001current,Digits);
SAR0009previous=NormalizeDouble(SAR0009previous,Digits);
SAR0009current=NormalizeDouble(SAR0009current,Digits);
SAR0015previous=NormalizeDouble(SAR0015previous,Digits);
SAR0015current=NormalizeDouble(SAR0015current,Digits);
SAR0025previous=NormalizeDouble(SAR0025previous,Digits);
SAR0025current=NormalizeDouble(SAR0025current,Digits);
SAR0040previous=NormalizeDouble(SAR0040previous,Digits);
SAR0040current=NormalizeDouble(SAR0040current,Digits);
SAR0066previous=NormalizeDouble(SAR0066previous,Digits);
SAR0066current=NormalizeDouble(SAR0066current,Digits);
SAR02previous=NormalizeDouble(SAR02previous,Digits);
SAR02current=NormalizeDouble(SAR02current,Digits);
PrimeTimeUp=NormalizeDouble(PrimeTimeUp,Digits);
PrimeTimeDown=NormalizeDouble(PrimeTimeDown,Digits);
iZeroAlphaUp=NormalizeDouble(iZeroAlphaUp,Digits);
iZeroAlphaDown=NormalizeDouble(iZeroAlphaDown,Digits);
iZeroAlphaUp5=NormalizeDouble(iZeroAlphaUp5,Digits);
iZeroAlphaDown5=NormalizeDouble(iZeroAlphaDown5,Digits);
OpenPrice=NormalizeDouble(OpenPrice,Digits);
TrendMagicUp=NormalizeDouble(TrendMagicUp,Digits);
TrendMagicDown=NormalizeDouble(TrendMagicDown,Digits);
HeikenAshiDownCurrent=NormalizeDouble(HeikenAshiDownCurrent,Digits);
HeikenAshiUpCurrent=NormalizeDouble(HeikenAshiUpCurrent,Digits);
HeikenAshiDownPrevious=NormalizeDouble(HeikenAshiDownPrevious,Digits);
HeikenAshiUpPrevious=NormalizeDouble(HeikenAshiUpPrevious,Digits);
smTRIXup=NormalizeDouble(smTRIXup,Digits);
smTRIXdown=NormalizeDouble(smTRIXdown,Digits);
smTRIXupPrevious2=NormalizeDouble(smTRIXupPrevious2,Digits);
smTRIXdownPrevious2=NormalizeDouble(smTRIXdownPrevious2,Digits);
smTRIXupPrevious3=NormalizeDouble(smTRIXupPrevious3,Digits);
smTRIXdownPrevious3=NormalizeDouble(smTRIXdownPrevious3,Digits);
smTRIXupPrevious6=NormalizeDouble(smTRIXupPrevious6,Digits);
smTRIXdownPrevious6=NormalizeDouble(smTRIXdownPrevious6,Digits);
smTRIXupPrevious7=NormalizeDouble(smTRIXupPrevious7,Digits);
smTRIXdownPrevious7=NormalizeDouble(smTRIXdownPrevious7,Digits);
smTRIXupPrevious8=NormalizeDouble(smTRIXupPrevious8,Digits);
smTRIXdownPrevious8=NormalizeDouble(smTRIXdownPrevious8,Digits);
smTRIXupPrevious9=NormalizeDouble(smTRIXupPrevious9,Digits);
smTRIXdownPrevious9=NormalizeDouble(smTRIXdownPrevious9,Digits);
smTRIXupPrevious10=NormalizeDouble(smTRIXupPrevious10,Digits);
smTRIXdownPrevious10=NormalizeDouble(smTRIXdownPrevious10,Digits);
sellsig=false;
buysig=false;
if(tradeopenbar<Time[0]){
if
((Close[0]-Open[0]>=3*Point && smTRIXup>0 && smTRIXdownPrevious<=-0 && iZeroAlphaUp>0.3 && iZeroAlphaUp5>0.3) ||
(Close[0]-Open[0]>=3*Point && smTRIXup>0 && smTRIXdownPrevious2<=-0 && iZeroAlphaUp>0.3 && iZeroAlphaUp5>0.3) ||
(Close[0]-Open[0]>=3*Point && smTRIXup>0 && smTRIXdownPrevious3<=-0 && iZeroAlphaUp>0.3 && iZeroAlphaUp5>0.3))
{
buysig=true;
}
if
((Open[0]-Ask>=3*Point && smTRIXdown<-0 && smTRIXupPrevious>=0 && iZeroAlphaDown<-0.3 && iZeroAlphaDown5<-0.3) ||
(Open[0]-Ask>=3*Point && smTRIXdown<-0 && smTRIXupPrevious2>=0 && iZeroAlphaDown<-0.3 && iZeroAlphaDown5<-0.3) ||
(Open[0]-Ask>=3*Point && smTRIXdown<-0 && smTRIXupPrevious3>=0 && iZeroAlphaDown<-0.3 && iZeroAlphaDown5<-0.3))
{
sellsig=true;
}
}
closebuy=false;
closesell=false;
if (Bid<iMA144) {
closebuy=true;
}
if (Ask>iMA144) {
closesell=true;
}
}
datetime CheckForOpen(datetime orderopenbar) {
int res,ct;
datetime result = orderopenbar;
ct=Hour()*100+Minute();
if
( !((ct>=TimeStart1 && ct<TimeStop1) || (ct>=TimeStart2 && ct<TimeStop2) ||
(ct>=TimeStart3 && ct<TimeStop3) || (ct>=TimeStart4 && ct<TimeStop4)) ) return(result);
double takeProfit;
double SetLots=0;
string EAComment='';
//---- sell conditions
if(sellsig && lastsig!=-1) {
res=0;
tries=0;
while (res<=0 && tries<OrderTriesNumber) {
while(!IsTradeAllowed()) Sleep(5000);
RefreshRates();
if(TakeProfit > MarketInfo(Symbol(), MODE_STOPLEVEL))
takeProfit = Bid-TakeProfit*Point;
else
takeProfit = 0;
SetLots=LotsRisk(StopLoss);
EAComment="TimeWave EURUSD M15";
res=OrderSend(Symbol(),OP_SELL,SetLots,Bid,slippage,Bid+StopLoss*Point,
takeProfit,EAComment,myMagic,0,DeepPink);
if (res<0)
Print("Error opening SELL order : ",ErrorDescription(GetLastError()));
else
result = Time[0]; // return this bar open time.
tries++;
}
lastsig= 0;
return(result);
}
//---- buy conditions
if(buysig && lastsig!=1) {
res=0;
tries=0;
while (res<=0 && tries<OrderTriesNumber) {
while(!IsTradeAllowed()) Sleep(5000);
RefreshRates();
if(TakeProfit > MarketInfo(Symbol(), MODE_STOPLEVEL))
takeProfit = Ask+TakeProfit*Point;
else
takeProfit = 0;
SetLots=LotsRisk(StopLoss);
EAComment="TimeWave EURUSD M15";
res=OrderSend(Symbol(),OP_BUY,LotsRisk(StopLoss),Ask,slippage,Ask-StopLoss*Point,
takeProfit,EAComment,myMagic,0,Yellow);
if (res<0)
Print("Error opening BUY order : ",ErrorDescription(GetLastError()));
else
result = Time[0]; // return this bar open Time
tries++;
}
lastsig = 0;
return(result);
}
return(result);
}
//+------------------------------------------------------------------+
//| Check for close order conditions |
//+------------------------------------------------------------------+
void CheckForClose() {
bool bres; int tr;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()!=myMagic || OrderSymbol()!=Symbol()) continue;
//---- check order type
if(OrderType()==OP_BUY)
{
if (closebuy) {
bres=false;
tries=0;
while (!bres && tries<OrderTriesNumber) {
while(tr<7 && !IsTradeAllowed()) { tr++; Sleep(5000); }
RefreshRates();
bres=OrderClose(OrderTicket(),OrderLots(),Bid,slippage,White);
Sleep(3000);
if (!bres) Print("Error closing order : ",ErrorDescription(GetLastError()));
tries++;
}
}
else
if(PartialClosing) PartialClosingExe();
break;
}
if(OrderType()==OP_SELL)
{
if (closesell) {
bres=false;
tries=0;
while (!bres && tries<OrderTriesNumber) {
while(tr<7 && !IsTradeAllowed()) { tr++; Sleep(5000); }
RefreshRates();
bres=OrderClose(OrderTicket(),OrderLots(),Ask,slippage,White);
Sleep(3000);
if (!bres) Print("Error closing order : ",ErrorDescription(GetLastError()));
tries++;
}
}
else
if(PartialClosing) PartialClosingExe();
break;
}
}
}
void BreakEvenStop() {
bool bres;
double StopLoss;
if ( BreakEvenStop > 2 ) {
for (int i = 0; i < OrdersTotal(); i++) {
if ( OrderSelect (i, SELECT_BY_POS) == false ) continue;
if ( OrderSymbol() != Symbol() || OrderMagicNumber() != myMagic ) continue;
if ( OrderType() == OP_BUY ) {
if ( (Bid < OrderOpenPrice()+BreakEvenStop*Point) ) return;
StopLoss = OrderOpenPrice();
if ( StopLoss > OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss+5*Point, OrderTakeProfit(), 0, White);
Sleep(3000);
if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError()));
}
}
if ( OrderType() == OP_SELL ) {
if ( (Ask > OrderOpenPrice()-BreakEvenStop*Point) ) return;
StopLoss = OrderOpenPrice();
if ( StopLoss < OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss-5*Point, OrderTakeProfit(), 0, White);
Sleep(3000);
if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError()));
}
}
}
}
return;
}
void TrailingStop() {
bool bres;
double StopLoss;
if ( TrailingStop > MarketInfo(Symbol(), MODE_STOPLEVEL)) {
for (int i = 0; i < OrdersTotal(); i++) {
if ( OrderSelect (i, SELECT_BY_POS) == false ) continue;
if ( OrderSymbol() != Symbol() || OrderMagicNumber() != myMagic ) continue;
if ( OrderType() == OP_BUY ) {
if ( (Bid < OrderStopLoss()+TrailingStop*Point) ) return;
StopLoss = Bid-TrailingStop*Point;
if ( StopLoss > OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White);
Sleep(3000);
if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError()));
}
}
if ( OrderType() == OP_SELL ) {
if ( (Ask > OrderStopLoss()-TrailingStop*Point) ) return;
StopLoss = Ask+TrailingStop*Point;
if ( StopLoss < OrderStopLoss() ) {
bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White);
Sleep(3000);
if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError()));
}
}
}
}
return;
}
double RoundLots(string S, double P)
{
double value=P;
double MinimalLot=0;
MinimalLot=MarketInfo(S,MODE_MINLOT);
if(MinimalLot<=0)
{
RefreshRates();
return(-1);
}
value=MathFloor(P/MinimalLot)*MinimalLot;
return(value);
}
//+------------------------------------------------------------------+
//| Linear closing of position |
//+------------------------------------------------------------------+
void PartialClosingExe()
{
int Profit=0;
if(OrderType()==OP_BUY) Profit=MathRound((Bid-OrderOpenPrice())/Point);
if(OrderType()==OP_SELL) Profit=MathRound((OrderOpenPrice()-Ask)/Point);
if(Profit<=0) return;
int PipStep=MathFloor(TakeProfit/TPDivide);
if(PipStep<1) PipStep=1;
if(PipStep>TakeProfit) PipStep=TakeProfit;
double LotPercent=1.00/TPDivide;
if(LotPercent>1.00) LotPercent=1.00;
if(TPDivide>TakeProfit && TakeProfit>0) LotPercent=1.00/TakeProfit;
double FirstPosition=LotsRisk(StopLoss);
double CutLots=FirstPosition*LotPercent*MathFloor(Profit/PipStep);
CutLots=RoundLots(Symbol(),CutLots);
if(CutLots<=0) return;
CutLots=CutLots-(FirstPosition-OrderLots());
if(CutLots<=0) return;
if(OrderLots()<CutLots) CutLots=OrderLots();
if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),CutLots,Bid,slippage,White);
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),CutLots,Ask,slippage,White);
return;
}
void start() {
static datetime TradeOpenBar;
//---- check for history and trading
if(Bars<100 || IsTradeAllowed()==false) return;
//---- check for signals
CheckForSignals(TradeOpenBar);
//---- calculate open orders by current symbol
if (CalculateCurrentOrders(Symbol())==0)
TradeOpenBar = CheckForOpen(TradeOpenBar);
else
CheckForClose();
BreakEvenStop();
TrailingStop();
}
//+------------------------------------------------------------------+ Attached File(s)
change the future, not the past