Hi,
Any help is greatly appreciated. A big thank you to Hayseed, and Kenny to name just a few for helping me thus far.
I have an EA attached that is only supposed to go long/short upon close[0] above/below the superTrend indicator. Maybe it is just an issue with the backtester, but it seems to be using a different bar close[0] period as it enters me anytime it crosses the superTrend indicator?
Please help!
Here is the main issue I think:
Any help is greatly appreciated. A big thank you to Hayseed, and Kenny to name just a few for helping me thus far.
I have an EA attached that is only supposed to go long/short upon close[0] above/below the superTrend indicator. Maybe it is just an issue with the backtester, but it seems to be using a different bar close[0] period as it enters me anytime it crosses the superTrend indicator?
Please help!
Here is the main issue I think:
QuoteDislikedif((Close[0] + Spread) <= DownTrend && (Close[1] - Spread) > DownTrend)
{
Inserted Code
//+------------------------------------------------------------------+
//| SuperTrend V1.mq4 |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
extern bool Direction = 1; //0 = long, 1 = short
extern int Periods = 3; //Number of Bars to calculate ATR, smaller number = lower atr
extern double Multiplier = 1.25; //Average True Range of change in trend calculation
extern int TimeFrame = 0; //Timeframe, 0 = current timeframe, 5 = 5MIN, 60 = 60MIN, 240 = 4HR, etc..
extern double MartingaleMultiplier = 1.5; //Martingale Multiplier
extern int MinimumProfitOfBasket = 0.01; //Minimum profit before exit of basket trades
extern int Slippage = 99; //Slippage for entries, smaller time frames, smaller slippage
extern int TypeOfEntry = 0; //0 = buy, 1 = sell, Forced Entry of only one type--Non-Functional (FUTURE)
extern double StartingLots = 0.01; //Starting # of lots before Martingale
extern int MagicNumber = 0; //Magic Number, 0 is default
bool SuccessfulOrder;
string TrendDirection = "No Direction YET!",
Comments = "SuperTrend Omni-Directional";
int NumberOrdersLong,
NumberOrdersShort;
double Spread,
UpTrend,
DownTrend,
Pip,
LotDigits,
BasketProfit,
BasketRecovery;
color OpenOrderColor = Blue,
ClosedOrderColor = Red;
///Put in Magic # random
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//setting up for future calls and 4/5 digit brokers
Pip = Point;
if (Digits == 3 || Digits == 5){Pip *= 10;}
if (MarketInfo(Symbol(),MODE_LOTSTEP) == 0.01){LotDigits = 2;}
Spread = Ask-Bid;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
RefreshRates();
GetCurrentOrdersProfit();
//PipRecovery();
ScreenComments();
UpTrend = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,0,1);
DownTrend = iCustom(NULL, 0, "SuperTrend",Periods,Multiplier,TimeFrame,1,1);
if(!Direction) //Direction Long Only
{
//if(Close[0] >= UpTrend && Close[1] < UpTrend && Open[0] > UpTrend)
if((Close[0] - Spread) >= UpTrend && (Close[1] + Spread) < UpTrend)
{
InitiateEntry(0);
TrendDirection = "Long";
Print("Trend has changed to LONG");
}
//if(Close[0] <= DownTrend && Close[1] > DownTrend && Open[0] < DownTrend)
if((Close[0] + Spread) <= DownTrend && (Close[1] - Spread) > DownTrend)
{
CloseOrder(0);
TrendDirection = "Short";
Print("Trend has changed to SHORT");
}
}
else //Direction Short Only
{
//if(Close[0] <= DownTrend && Close[1] > DownTrend && Open[0] < DownTrend)
if((Close[0] + Spread) <= DownTrend && (Close[1] - Spread) > DownTrend)
{
InitiateEntry(1);
TrendDirection = "Short";
Print("Trend has changed to SHORT");
}
//if(Close[0] >= UpTrend && Close[1] < UpTrend && Open[0] > UpTrend)
if((Close[0] - Spread) >= UpTrend && (Close[1] + Spread) < UpTrend)
{
CloseOrder(1);
TrendDirection = "Long";
Print("Trend has changed to LONG");
}
}
//----
return(0);
}
//==============Functions===========Functions=++++++++++++++++Functions++++++++Functions+++====Functions=====Functions============
//FunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctionsFunctions++
//---+++++++++++++++++++++++++++++++++++++++++++
void InitiateEntry(int EntryType)
//---+++++++++++++++++++++++++++++++++++++++++++
{
bool Success;
BasketProfit = 0.00;
double LargestLotSize;
for(int i = 0; i < OrdersHistoryTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
if(OrderType() == Direction && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
if(OrderLots() > LargestLotSize)
{
LargestLotSize = OrderLots();
}
BasketProfit = OrderProfit() + OrderCommission() + OrderSwap();
if(OrderLots() == StartingLots) break;
}
}
}
if(BasketProfit < 0)
{
if((OrderProfit() + OrderSwap() + OrderCommission()) > 0)
{
StartingLots = LargestLotSize;
Print("Current Order is Profitable, Next Order = Current Order");
}
else
{
StartingLots = LargestLotSize * Multiplier;
Print("Current Order is Un-profitable, Next Order will be Multiplied");
}
}
if(OrdersTotal() < 1)
{
Success = OrderSend(Symbol(),Direction,StartingLots,Ask,Slippage,0,0,Comments,MagicNumber,0,OpenOrderColor);
if(Success)return(0);
}
}
//---+++++++++++++++++++++++++++++++++++++++++++
void CloseOrder(int EntryType)
{
bool Success;
for (int co=OrdersTotal() - 1; co >= 0; co--)
{
if (OrderSelect(co, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == EntryType)
{
Success = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,ClosedOrderColor);
if(Success)break;
}
}
}
return(0);
}
//---+++++++++++++++++++++++++++++++++++++++++++
//---+++++++++++++++++++++++++++++++++++++++++++
double GetCurrentOrdersProfit()
//---+++++++++++++++++++++++++++++++++++++++++++
{
//Verifying the current values of Long's and Short's+++++++++++++++++++++++++++++++++++++++++++++++++++
if(OrdersTotal() > 0)
{
for(int i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
{
BasketProfit = OrderProfit() + OrderCommission() + OrderSwap();
}
}
}
}
}
void PipRecovery()
{
//This function will run and close out all baskets that are profitable and leave startinglot size in same direction.
//This will close the existing order and open .01 lot in the same direction (must account for spread).
//Put in a filter to turn on/off or after so many levels?
}
string ScreenComments()
{
Comment("UpTrend: ", UpTrend, "n", "DownTrend: ", DownTrend, "n", "Trade Direction: ", TrendDirection, "n",
"Basket Value: ", BasketProfit, "n","Basket Recovery: ", BasketRecovery, "n","Difference: $", BasketProfit-BasketRecovery, "n",
"Spread: ", Spread/Point
);
} Attached File(s)
We are our own best indicator.