Fantastic spot JP. Thanks.theforexedge » Wed Dec 10, 2014 11:20 pm wrote:Steve
Thanks for the recent additions including the ATR![]()
I've just setup a few demo's to test the ATR Stoploss & TakeProfit and noticed what might be a cut & paste error...
Anyhow guys, if you haven't been and do not intend using ATR for your tp/sl then it doesn't matter. Download the next update when it suits you. If your are using ATR, the V 1v is in post 1. If you enjoy making your own changes, then copy this over the existing double CalculateTakeProfit(int type, double price, string comment)
Code: Select all
double CalculateTakeProfit(int type, double price, string comment)
{
//Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
double take;
RefreshRates();
if (type == OP_BUY)
{
//Trend trades
if (comment == TrendTradeComment)
{
//Atr take profit
if (TrendAtrPeriod > 0)
{
TrendTakeProfit = (GetAtr(Symbol(), TrendAtrTimeFrame, TrendAtrPeriod, 0) * factor) * TrendAtrTpMultiplier;
}//if (TrendAtrPeriod > 0)
if (!CloseEnough(TrendTakeProfit, 0) )
{
take = price + (TrendTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(TrendTakeProfit, 0) )
}//if (comment == TrendTradeComment)
//Range trades
if (comment == RangeTradeComment)
{
//Atr take profit
if (RangeAtrPeriod > 0)
{
RangeTakeProfit = (GetAtr(Symbol(), RangeAtrTimeFrame, RangeAtrPeriod, 0) * factor) * RangeAtrTpMultiplier;
}//if (RangeAtrPeriod > 0)
if (!CloseEnough(RangeTakeProfit, 0) )
{
take = price + (RangeTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(RangeTakeProfit, 0) )
}//if (comment == RangeTradeComment)
//Rad trades
if (comment == RadTradeComment)
{
//Atr take profit
if (TrendAtrPeriod > 0)
{
RadTakeProfit = (GetAtr(Symbol(), TrendAtrTimeFrame, TrendAtrPeriod, 0) * factor) * TrendAtrTpMultiplier;
}//if (TrendAtrPeriod > 0)
if (!CloseEnough(RadTakeProfit, 0) )
{
take = price + (RadTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(RadTakeProfit, 0) )
}//if (comment == RadTradeComment)
//Wave trades
if (comment == WaveTradeComment)
if (!CloseEnough(WaveMultiTakeProfit, 0) )
{
take = price + (WaveMultiTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(WaveMultiTakeProfit, 0) )
if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take + (HiddenPips / factor), Digits);
}//if (type == OP_BUY)
if (type == OP_SELL)
{
//Trend trades
if (comment == TrendTradeComment)
{
//Atr take profit
if (TrendAtrPeriod > 0)
{
TrendTakeProfit = (GetAtr(Symbol(), TrendAtrTimeFrame, TrendAtrPeriod, 0) * factor) * TrendAtrTpMultiplier;
}//if (TrendAtrPeriod > 0)
if (!CloseEnough(TrendTakeProfit, 0) )
{
take = price - (TrendTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(TrendTakeProfit, 0) )
}//if (comment == TrendTradeComment)
//Range trades
if (comment == RangeTradeComment)
{
//Atr take profit
if (RangeAtrPeriod > 0)
{
RangeTakeProfit = (GetAtr(Symbol(), RangeAtrTimeFrame, RangeAtrPeriod, 0) * factor) * RangeAtrTpMultiplier;
}//if (RangeAtrPeriod > 0)
if (!CloseEnough(RangeTakeProfit, 0) )
{
take = price - (RangeTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(RangeTakeProfit, 0) )
}//if (comment == RangeTradeComment)
//Rad trades
if (comment == RadTradeComment)
{
//Atr take profit
if (RadAtrPeriod > 0)
{
RadTakeProfit = (GetAtr(Symbol(), RadAtrTimeFrame, RadAtrPeriod, 0) * factor) * RadAtrTpMultiplier;
}//if (RadAtrPeriod > 0)
if (!CloseEnough(RadTakeProfit, 0) )
{
take = price - (RadTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(RadTakeProfit, 0) )
}//if (comment == RadTradeComment)
//Wave trades
if (comment == WaveTradeComment)
if (!CloseEnough(WaveMultiTakeProfit, 0) )
{
take = price - (WaveMultiTakeProfit / factor);
HiddenTakeProfit = take;
}//if (!CloseEnough(WaveMultiTakeProfit, 0) )
if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take - (HiddenPips / factor), Digits);
}//if (type == OP_SELL)
return(take);
}//End double CalculateTakeProfit(int type)