Actually, it didnt work. Let me show:
That's the code I made:
What did I do wrong, Mr. Trash?
My best regards.
That's the code I made:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("MA BackTest");
ArrayMA = ParamField( "Array" , 3 );
PeriodosMA = Param( "Períodos" , 28 , 2 , 100 , 1 );
ProjectedMA_Period = PeriodosMA - 1;
OriginalMA = MA( ArrayMA , PeriodosMA );
//MA where i want to enter as the price touch it
ProjectedMA = Ref ( MA( ArrayMA , ProjectedMa_Period ) , -1 );
//this will show the exacly point where the MA will be when prices touch it
Plot( OriginalMA , "Média " + PeriodosMA + ")" , colorRed ) ;
Plot( ProjectedMA , "Buy/Sell Point" , colorWhite , styleDots | styleNoLine);
/*I activated the option: ACTIVATE STOPS IMMEDIATELY. I understood that after entering the trade, it checks:
1 - if the low activate the stop loss. If not...
2 - it checks if the high activate the take profit.
Actually, is there a way to make only the first check true? I mean:
1 - check if the low activate the stop loss in the entry bar...
2 - check if the high activate the take profit only on the next candle (the one after the entry bar).
What do you think? The reason I want it like this is because I want the backtest to assume the
worst possible scenario. Since its EOD data, I can't know for certain if the high of the
candle was achieved after I entered in the trade. So I want to assume it made the
high (takeprofit) before the entry signal (but I want to assume, also, that
the StopLoss was achieved after the entry signal). */
//Delay set by Mr. Trash Example:
tradedelay = 0;
if ( tradedelay > 0 )
{
entryprice = Open;
immediatestop = 1;
}
else
{
entryprice = Close;
immediatestop = 0;
}
SetOption( "ActivateStopsImmediately", immediatestop );
//Now the Buy Signal
BuySetup = (Ref( Low , -1 ) > Ref( OriginalMA , -1 )) AND (Low <= ProjectedMA);
//the prices must be above the MA for a buysetup
BuyPrice = ProjectedMA;
//I want to enter at the exact point of touch
Buy = Ref( BuySetup, -tradedelay );
Sell = 0;
StopGain_Multiplicator = Optimize( "StopGain_Mult" , 10 , 10 , 40 , 1 );
StopLoss_Multiplicator = Optimize( "StopLoss_Mult" , 10 , 10 , 40 , 1 );
StopLoss = StopLoss_Multiplicator * TickSize;
StopGain = StopGain_Multiplicator * TickSize;
ApplyStop(stopTypeLoss , stopModePoint , stoploss , 1 , False , 0 ) ;
ApplyStop( stopTypeProfit , stopModePoint , stopgain , 1 , False , 0 );
//I want to sell by stop loss of 100 points or take profit of 100 points
_SECTION_END();
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("MA BackTest");
ArrayMA = ParamField( "Array" , 3 );
PeriodosMA = Param( "Períodos" , 28 , 2 , 100 , 1 );
ProjectedMA_Period = PeriodosMA - 1;
OriginalMA = MA( ArrayMA , PeriodosMA );
//MA where i want to enter as the price touch it
ProjectedMA = Ref ( MA( ArrayMA , ProjectedMa_Period ) , -1 );
//this will show the exacly point where the MA will be when prices touch it
Plot( OriginalMA , "Média " + PeriodosMA + ")" , colorRed ) ;
Plot( ProjectedMA , "Buy/Sell Point" , colorWhite , styleDots | styleNoLine);
/*I activated the option: ACTIVATE STOPS IMMEDIATELY. I understood that after entering the trade, it checks:
1 - if the low activate the stop loss. If not...
2 - it checks if the high activate the take profit.
Actually, is there a way to make only the first check true? I mean:
1 - check if the low activate the stop loss in the entry bar...
2 - check if the high activate the take profit only on the next candle (the one after the entry bar).
What do you think? The reason I want it like this is because I want the backtest to assume the
worst possible scenario. Since its EOD data, I can't know for certain if the high of the
candle was achieved after I entered in the trade. So I want to assume it made the
high (takeprofit) before the entry signal (but I want to assume, also, that
the StopLoss was achieved after the entry signal). */
//Delay set by Mr. Trash Example:
tradedelay = 0;
if ( tradedelay > 0 )
{
entryprice = Open;
immediatestop = 1;
}
else
{
entryprice = Close;
immediatestop = 0;
}
SetOption( "ActivateStopsImmediately", immediatestop );
//Now the Buy Signal
BuySetup = (Ref( Low , -1 ) > Ref( OriginalMA , -1 )) AND (Low <= ProjectedMA);
//the prices must be above the MA for a buysetup
BuyPrice = ProjectedMA;
//I want to enter at the exact point of touch
Buy = Ref( BuySetup, -tradedelay );
Sell = 0;
StopGain_Multiplicator = Optimize( "StopGain_Mult" , 10 , 10 , 40 , 1 );
StopLoss_Multiplicator = Optimize( "StopLoss_Mult" , 10 , 10 , 40 , 1 );
StopLoss = StopLoss_Multiplicator * TickSize;
StopGain = StopGain_Multiplicator * TickSize;
ApplyStop(stopTypeLoss , stopModePoint , stoploss , 1 , False , 0 ) ;
ApplyStop( stopTypeProfit , stopModePoint , stopgain , 1 , False , 0 );
//I want to sell by stop loss of 100 points or take profit of 100 points
_SECTION_END();
What did I do wrong, Mr. Trash?
My best regards.