Oops. We are up to version 1n now.phil_trade wrote:Hi Steve
I think TradeRange Test is missing in LookForWeeklyCrossRangeTrade()
Am'I right ?
Philippe
Nice one again, Philippe. Thanks.
Oops. We are up to version 1n now.phil_trade wrote:Hi Steve
I think TradeRange Test is missing in LookForWeeklyCrossRangeTrade()
Am'I right ?
Philippe
You have to save it first, then reload it from within the platform.spotdespot wrote:I seem unable to edit this latest version for some reason? Is there an obvious setting I am missing. I can load it in the MetaEditor but cannot make any changes as I usually do with the default settings......am I about to receive a dummy award??
SteveHopwood wrote:You have to save it first, then reload it from within the platform.spotdespot wrote:I seem unable to edit this latest version for some reason? Is there an obvious setting I am missing. I can load it in the MetaEditor but cannot make any changes as I usually do with the default settings......am I about to receive a dummy award??
Don't you just love it when something simple takes an hour and a half? When I download an mq4 file into the editor, it always arrives as read-only. It has never saved as read-only before.spotdespot wrote:SteveHopwood wrote:You have to save it first, then reload it from within the platform.spotdespot wrote:I seem unable to edit this latest version for some reason? Is there an obvious setting I am missing. I can load it in the MetaEditor but cannot make any changes as I usually do with the default settings......am I about to receive a dummy award??
I'm not that much of a dummy Steve! I saved, restarted Empty4, recompiled it, saved as a different name, restarted again, tried a different criminal....same story. I might try the techies secret weapon & reboot....
I suspect somewhere my "system" thinks it is open already.....still doesn't quite make sense but what does with Empty4?
EDIT: Actually it turns out I am a dummy after all - who knew. For some reason the EA saved with "Read Only" attributes - now that would have been a good place to start looking when I couldn't edit it....doh.
Code: Select all
void LookForWeeklyCrossRangeTrade()
{
//Called from LookForTradingOpportunities() if magic = 0, indicating no trades have been triggered by other systems.
//Looks for D1/H4 Slopes both ranging, or some part of the D1 candle tradubg within the moving averages
if (!TradeRange) return;//Usaer option to trade this way.
//Only allow one open trade when the market is ranging.
if (OpenTrades > 0) return;
bool NowRanging = false;
if (D1SlopeTrend == ranging && LtfSlopeTrend == ranging) NowRanging = true;
if (!NowRanging)
{
double Hma = GetHighestMovingAverage(PERIOD_D1);
double Lma = GetLowestMovingAverage(PERIOD_D1);
}//if (!NowRanging)
//Is any part of the D1 candle trading within the moving averages?
if (iLow(NULL, PERIOD_D1, 0) > Hma || iHigh(NULL, PERIOD_D1, 0) < Lma) return;Code: Select all
if (!NowRanging)
{
double Hma = GetHighestMovingAverage(PERIOD_D1);
double Lma = GetLowestMovingAverage(PERIOD_D1);
//Is any part of the D1 candle trading within the moving averages?
if (iLow(NULL, PERIOD_D1, 0) > Hma || iHigh(NULL, PERIOD_D1, 0) < Lma) return;
}//if (!NowRanging)Code: Select all
double CalculateStopLoss(int type)
{
//Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
double stop, price;
RefreshRates();
double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL);
/*
#define BbRangeTrade "BB Range trade"
*/
if (type == OP_BUY)
{
price = Ask;
if (StopLoss > 0)
{
stop = NormalizeDouble(price - (StopLoss * Point), Digits);
HiddenStopLoss = stop;
}//if (StopLoss > 0)
if (StopLoss == 0)
{
//BB Range trade. Use Bb extent
if (TradeOrigin == BbRangeTrade)
{
double extent = BbUpper - BbLower;
stop = NormalizeDouble(BbLower - extent, Digits);
}//if (TradeOrigin == BbRangeTrade)
//Wpc range trade. Uses S1/S2 as sl
if (TradeOrigin == WpcRangeTrade)
{
stop = WS2;
if (VolatilityGroup < 4) stop = WS1;
}//if (TradeOrigin == WpcRangeTrade)
//D1 trend trade
if (TradeOrigin == D1TrendTrade)
{
stop = MS2;
if (VolatilityGroup < 4) stop = MS1;
}//if (TradeOrigin == D1TrendTrade)
//H4 trend trade
if (TradeOrigin == H4TrendTrade)
{
stop = WS2;
if (VolatilityGroup < 4) stop = WS1;
}//if (TradeOrigin == H4TrendTrade)
}//if (StopLoss == 0)
if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop - (HiddenPips * Point), Digits);
// Control stop level minima
if (Bid-stop <= Stoplevel*Point)
{
stop = Bid - (Stoplevel*Point);
}
}//if (type == OP_BUY)
if (type == OP_SELL)
{
price = Bid;
if (StopLoss > 0)
{
stop = NormalizeDouble(price + (StopLoss * Point), Digits);
HiddenStopLoss = stop;
}//if (StopLoss > 0)
if (StopLoss == 0)
{
//BB Range trade. Use Bb extent
if (TradeOrigin == BbRangeTrade)
{
extent = BbUpper - BbLower;
stop = NormalizeDouble(BbUpper + extent, Digits);
}//if (TradeOrigin == BbRangeTrade)
//Wpc range trade. Uses R1/R2 as sl
if (TradeOrigin == WpcRangeTrade)
{
stop = WR2;
if (VolatilityGroup < 4) stop = WR1;
}//if (TradeOrigin == WpcRangeTrade)
//D1 trend trade
if (TradeOrigin == D1TrendTrade)
{
stop = MR2;
if (VolatilityGroup < 4) stop = MR1;
}//if (TradeOrigin == D1TrendTrade)
//H4 trend trade
if (TradeOrigin == H4TrendTrade)
{
stop = WR2;
if (VolatilityGroup < 4) stop = WR1;
}//if (TradeOrigin == H4TrendTrade)
}//if (StopLoss == 0)
if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop + (HiddenPips * Point), Digits);
// Control stop level minima
if (stop-Ask <= Stoplevel*Point)
{
stop = Ask + (Stoplevel*Point);
}
}//if (type == OP_SELL)
return(stop);
}//End double CalculateStopLoss(int type)
double CalculateTakeProfit(int type, string origin)
{
//Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss
double take, price;
RefreshRates();
double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL);
if (type == OP_BUY)
{
price = Ask;
if (TakeProfit > 0)
{
take = NormalizeDouble(price + (TakeProfit * Point), Digits);
HiddenTakeProfit = take;
}//if (TakeProfit > 0)
//D1 trend trade
if (TradeOrigin == D1TrendTrade)
{
//Override any take profit choice if D1SlopeTrend is buy and hold
if (D1SlopeTrend == buyhold)
{
take = 0;
AdaptedBreakEven = true;
AdaptedJumpingStop = true;
}//if (D1SlopeTrend == buyhold)
//If D1 slope is not buy and hold, then set a tp based on the next full resistance level
if (D1SlopeTrend != buyhold)
{
//Work down through the Monthly Resistance levels until Bid is lower than the resistance.
//I have assumed that the market will be above the support levels, and can amend this easily if not.
if (price < MR3)
{
if (MR3 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR3;
}//if (price < MR3)
if (price < MR2)
{
if (MR2 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR2;
}//if (price < MR3)
if (price < MR1)
{
if (MR1 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR1;
}//if (price < MR3)
if (price < MonthlyPivot)
{
if (MonthlyPivot - price >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot;
}//if (price < MonthlyPivot)
}//if (D1SlopeTrend == buyhold)
}//if (TradeOrigin = D1Trend)
//H4 trend trade
if (TradeOrigin == H4TrendTrade)
{
//Override any take profit choice if D1SlopeTrend is buy and hold
if (D1SlopeTrend == buyhold)
{
take = 0;
AdaptedBreakEven = true;
AdaptedJumpingStop = true;
}//if (D1SlopeTrend == buyhold)
//D1 trend is not buy and hold, so set a tp based on the next resistance.
//This is weekly R1 for pairs in groups 1 to 3, R2 for the others.
if (D1SlopeTrend == buy)
{
take = WR2;
if (VolatilityGroup < 4) take = WR1;
}//if (D1SlopeTrend == buy)
}//if (TradeOrigin == H4TrendTrade)
//BB Range trade. Use Weekly pivot tp. Range trade should only be sent at
//MinimumRangeTakeProfit from the weekly pivot
if (TradeOrigin == BbRangeTrade)
{
take = WeeklyPivot;
}//if (TradeOrigin == RangeTrade)
//Wpc range trade. Uses R1/R2 as tp
if (TradeOrigin == WpcRangeTrade)
{
take = WR2;
if (VolatilityGroup < 4) take = WR1;
}//if (TradeOrigin == WpcRangeTrade)
if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take + (HiddenPips * Point), Digits);
// Control stop level minima
if (take-Ask <= Stoplevel*Point)
{
take = Ask + (Stoplevel*Point);
}
}//if (type == OP_BUY)
if (type == OP_SELL)
{
price = Bid;
if (TakeProfit > 0)
{
take = NormalizeDouble(price - (TakeProfit * Point), Digits);
HiddenTakeProfit = take;
}//if (TakeProfit > 0)
if (TradeOrigin == D1TrendTrade)
{
//Override any take profit choice if D1SlopeTrend is sell and hold
if (D1SlopeTrend == sellhold)
{
take = 0;
AdaptedBreakEven = true;
AdaptedJumpingStop = true;
}//if (D1SlopeTrend == buyhold)
//If D1 slope is not sell and hold, then set a tp based on the next full support level
if (D1SlopeTrend != buyhold)
{
//Work up through the Monthly support levels until Bid is higher than support. I have assumed that the
//market will be below the resistance levels, and can amend this easily if not.
if (price > MS3)
{
if (price - MS3 >= (MinD1TrendTradeTpPips * Point) ) take = MS3;
}//if (price > MS3)
if (price > MS2)
{
if (price - MS2 >= (MinD1TrendTradeTpPips * Point) ) take = MS2;
}//if (price > MS2)
if (price > MS1)
{
if (price - MS1 >= (MinD1TrendTradeTpPips * Point) ) take = MS1;
}//if (price > MS1)
if (price > MonthlyPivot)
{
if (price - MonthlyPivot >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot;
}//if (price > MonthlyPivot)
}//if (D1SlopeTrend == buyhold)
}//if (TradeOrigin == D1Trend)
//H4 trend trade
if (TradeOrigin == H4TrendTrade)
{
//Override any take profit choice if D1SlopeTrend is buy and hold
if (D1SlopeTrend == sellhold)
{
take = 0;
AdaptedBreakEven = true;
AdaptedJumpingStop = true;
}//if (D1SlopeTrend == buyhold)
//D1 trend is not buy and hold, so set a tp based on the next resistance.
//This is weekly R1 for pairs in groups 1 to 3, R2 for the others.
if (D1SlopeTrend == sell)
{
take = WS2;
if (VolatilityGroup < 4) take = WS1;
}//if (D1SlopeTrend == sell)
}//if (TradeOrigin == H4TrendTrade)
//BB Range trade. Use Weekly pivot tp. Range trade should only be sent at
//MinimumRangeTakeProfit from the weekly pivot
if (TradeOrigin == BbRangeTrade)
{
take = WeeklyPivot;
}//if (TradeOrigin == RangeTrade)
//Wpc range trade. Uses S1/S2 as tp
if (TradeOrigin == WpcRangeTrade)
{
take = WS2;
if (VolatilityGroup < 4) take = WS1;
}//if (TradeOrigin == WpcRangeTrade)
if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take - (HiddenPips * Point), Digits);
// Control stop level minima
if (Bid-take <= Stoplevel*Point)
{
take = Bid - (Stoplevel*Point);
}
}//if (type == OP_SELL)
return(take);
}//End double CalculateTakeProfit(int type, string origin)
Or people can use HiddenPips to have their stop loss pretty much where they want.phil_trade wrote:Steve
I had from time to time error 130 on modifyOrder for SL and TP like for BUY EURCHF 22/05/2012 22H13 GMT WPCrange trade on SlopeRanging because SL and TP too near from Bid.
Bid 1.20117 and R1 1.2011 R2 1.2013 S1 1.2003 S2 1.2001
So the trade was passed without SL and TP !
Some criminal and some pairs have very wide STOPLEVEL (40 pips minimum for EURCHF)
so I suggest to modify code like below. This solve for EURCHF with a trade with SL at 1.20055 and TP 1.20157 but may be you will prefer not to trade when Bid too near calculated SL and TP.
Philippe
Code: Select all
double CalculateStopLoss(int type) { //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss double stop, price; RefreshRates(); double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL); /* #define BbRangeTrade "BB Range trade" */ if (type == OP_BUY) { price = Ask; if (StopLoss > 0) { stop = NormalizeDouble(price - (StopLoss * Point), Digits); HiddenStopLoss = stop; }//if (StopLoss > 0) if (StopLoss == 0) { //BB Range trade. Use Bb extent if (TradeOrigin == BbRangeTrade) { double extent = BbUpper - BbLower; stop = NormalizeDouble(BbLower - extent, Digits); }//if (TradeOrigin == BbRangeTrade) //Wpc range trade. Uses S1/S2 as sl if (TradeOrigin == WpcRangeTrade) { stop = WS2; if (VolatilityGroup < 4) stop = WS1; }//if (TradeOrigin == WpcRangeTrade) //D1 trend trade if (TradeOrigin == D1TrendTrade) { stop = MS2; if (VolatilityGroup < 4) stop = MS1; }//if (TradeOrigin == D1TrendTrade) //H4 trend trade if (TradeOrigin == H4TrendTrade) { stop = WS2; if (VolatilityGroup < 4) stop = WS1; }//if (TradeOrigin == H4TrendTrade) }//if (StopLoss == 0) if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop - (HiddenPips * Point), Digits); // Control stop level minima if (Bid-stop <= Stoplevel*Point) { stop = Bid - (Stoplevel*Point); } }//if (type == OP_BUY) if (type == OP_SELL) { price = Bid; if (StopLoss > 0) { stop = NormalizeDouble(price + (StopLoss * Point), Digits); HiddenStopLoss = stop; }//if (StopLoss > 0) if (StopLoss == 0) { //BB Range trade. Use Bb extent if (TradeOrigin == BbRangeTrade) { extent = BbUpper - BbLower; stop = NormalizeDouble(BbUpper + extent, Digits); }//if (TradeOrigin == BbRangeTrade) //Wpc range trade. Uses R1/R2 as sl if (TradeOrigin == WpcRangeTrade) { stop = WR2; if (VolatilityGroup < 4) stop = WR1; }//if (TradeOrigin == WpcRangeTrade) //D1 trend trade if (TradeOrigin == D1TrendTrade) { stop = MR2; if (VolatilityGroup < 4) stop = MR1; }//if (TradeOrigin == D1TrendTrade) //H4 trend trade if (TradeOrigin == H4TrendTrade) { stop = WR2; if (VolatilityGroup < 4) stop = WR1; }//if (TradeOrigin == H4TrendTrade) }//if (StopLoss == 0) if (HiddenPips > 0 && stop > 0) stop = NormalizeDouble(stop + (HiddenPips * Point), Digits); // Control stop level minima if (stop-Ask <= Stoplevel*Point) { stop = Ask + (Stoplevel*Point); } }//if (type == OP_SELL) return(stop); }//End double CalculateStopLoss(int type) double CalculateTakeProfit(int type, string origin) { //Returns the stop loss for use in LookForTradingOpps and InsertMissingStopLoss double take, price; RefreshRates(); double Stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL); if (type == OP_BUY) { price = Ask; if (TakeProfit > 0) { take = NormalizeDouble(price + (TakeProfit * Point), Digits); HiddenTakeProfit = take; }//if (TakeProfit > 0) //D1 trend trade if (TradeOrigin == D1TrendTrade) { //Override any take profit choice if D1SlopeTrend is buy and hold if (D1SlopeTrend == buyhold) { take = 0; AdaptedBreakEven = true; AdaptedJumpingStop = true; }//if (D1SlopeTrend == buyhold) //If D1 slope is not buy and hold, then set a tp based on the next full resistance level if (D1SlopeTrend != buyhold) { //Work down through the Monthly Resistance levels until Bid is lower than the resistance. //I have assumed that the market will be above the support levels, and can amend this easily if not. if (price < MR3) { if (MR3 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR3; }//if (price < MR3) if (price < MR2) { if (MR2 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR2; }//if (price < MR3) if (price < MR1) { if (MR1 - price >= (MinD1TrendTradeTpPips * Point) ) take = MR1; }//if (price < MR3) if (price < MonthlyPivot) { if (MonthlyPivot - price >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot; }//if (price < MonthlyPivot) }//if (D1SlopeTrend == buyhold) }//if (TradeOrigin = D1Trend) //H4 trend trade if (TradeOrigin == H4TrendTrade) { //Override any take profit choice if D1SlopeTrend is buy and hold if (D1SlopeTrend == buyhold) { take = 0; AdaptedBreakEven = true; AdaptedJumpingStop = true; }//if (D1SlopeTrend == buyhold) //D1 trend is not buy and hold, so set a tp based on the next resistance. //This is weekly R1 for pairs in groups 1 to 3, R2 for the others. if (D1SlopeTrend == buy) { take = WR2; if (VolatilityGroup < 4) take = WR1; }//if (D1SlopeTrend == buy) }//if (TradeOrigin == H4TrendTrade) //BB Range trade. Use Weekly pivot tp. Range trade should only be sent at //MinimumRangeTakeProfit from the weekly pivot if (TradeOrigin == BbRangeTrade) { take = WeeklyPivot; }//if (TradeOrigin == RangeTrade) //Wpc range trade. Uses R1/R2 as tp if (TradeOrigin == WpcRangeTrade) { take = WR2; if (VolatilityGroup < 4) take = WR1; }//if (TradeOrigin == WpcRangeTrade) if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take + (HiddenPips * Point), Digits); // Control stop level minima if (take-Ask <= Stoplevel*Point) { take = Ask + (Stoplevel*Point); } }//if (type == OP_BUY) if (type == OP_SELL) { price = Bid; if (TakeProfit > 0) { take = NormalizeDouble(price - (TakeProfit * Point), Digits); HiddenTakeProfit = take; }//if (TakeProfit > 0) if (TradeOrigin == D1TrendTrade) { //Override any take profit choice if D1SlopeTrend is sell and hold if (D1SlopeTrend == sellhold) { take = 0; AdaptedBreakEven = true; AdaptedJumpingStop = true; }//if (D1SlopeTrend == buyhold) //If D1 slope is not sell and hold, then set a tp based on the next full support level if (D1SlopeTrend != buyhold) { //Work up through the Monthly support levels until Bid is higher than support. I have assumed that the //market will be below the resistance levels, and can amend this easily if not. if (price > MS3) { if (price - MS3 >= (MinD1TrendTradeTpPips * Point) ) take = MS3; }//if (price > MS3) if (price > MS2) { if (price - MS2 >= (MinD1TrendTradeTpPips * Point) ) take = MS2; }//if (price > MS2) if (price > MS1) { if (price - MS1 >= (MinD1TrendTradeTpPips * Point) ) take = MS1; }//if (price > MS1) if (price > MonthlyPivot) { if (price - MonthlyPivot >= (MinD1TrendTradeTpPips * Point) ) take = MonthlyPivot; }//if (price > MonthlyPivot) }//if (D1SlopeTrend == buyhold) }//if (TradeOrigin == D1Trend) //H4 trend trade if (TradeOrigin == H4TrendTrade) { //Override any take profit choice if D1SlopeTrend is buy and hold if (D1SlopeTrend == sellhold) { take = 0; AdaptedBreakEven = true; AdaptedJumpingStop = true; }//if (D1SlopeTrend == buyhold) //D1 trend is not buy and hold, so set a tp based on the next resistance. //This is weekly R1 for pairs in groups 1 to 3, R2 for the others. if (D1SlopeTrend == sell) { take = WS2; if (VolatilityGroup < 4) take = WS1; }//if (D1SlopeTrend == sell) }//if (TradeOrigin == H4TrendTrade) //BB Range trade. Use Weekly pivot tp. Range trade should only be sent at //MinimumRangeTakeProfit from the weekly pivot if (TradeOrigin == BbRangeTrade) { take = WeeklyPivot; }//if (TradeOrigin == RangeTrade) //Wpc range trade. Uses S1/S2 as tp if (TradeOrigin == WpcRangeTrade) { take = WS2; if (VolatilityGroup < 4) take = WS1; }//if (TradeOrigin == WpcRangeTrade) if (HiddenPips > 0 && take > 0) take = NormalizeDouble(take - (HiddenPips * Point), Digits); // Control stop level minima if (Bid-take <= Stoplevel*Point) { take = Bid - (Stoplevel*Point); } }//if (type == OP_SELL) return(take); }//End double CalculateTakeProfit(int type, string origin)