NexusFi: Find Your Edge


Home Menu

 





Turning an indicator into a strategy issue


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one FastNCurious with 6 posts (0 thanks)
    2. looks_two ABCTG with 4 posts (3 thanks)
    3. looks_3 Donovan2580 with 2 posts (2 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 5,608 views
    2. thumb_up 5 thanks given
    3. group 4 followers
    1. forum 12 posts
    2. attach_file 0 attachments




 
Search this Thread

Turning an indicator into a strategy issue

  #1 (permalink)
Donovan2580
Port St. Lucie, FL
 
Posts: 36 since Jul 2016
Thanks Given: 22
Thanks Received: 37

Hello,

I am having some problems turning an indicator I have written into a strategy, so I can back-test it.

The indicator plots my entries and exits perfectly, but when I change it into a strategy something changes.

Some of the trades come in perfectly, but I get random trades that I cannot explain, late entries, late exits, etc.

Is there something that I am missing or doing wrong?

I am looking at tick bar charts, on the EMini.

Here is the code for both the indicator and the strategy

Thanks in advance,

Donovan


Indicator



Inputs:
TCLen(10),
MA1(23),
MA2(50),
Trigger_Long (99.75),
Trigger_Short (0.25);

Variables:
MP(0);//MP = marketposition

//Value1
Value1 = (_SchaffTC(TCLen,MA1,MA2));


//Long Entry
If MP=0 and Value1 > Trigger_Long then begin Plot1(High + .5, "LE",Red);
MP = 1;
End;

//Long Exit
If MP =1 and Value1 < Trigger_Long then begin Plot2(High + .5, "LX",Magenta);
MP = 0;
End;


//Short Entry
If MP = 0 and Value1 < Trigger_Short then begin Plot3(Low - .5, "SE",white);
MP = -1;
End;

//Short Exit
If MP = -1 and Value1 > Trigger_Short then begin Plot4(Low - .5, "SX",darkgray);
MP = 0;
End;


_________________________________________

Strategy



[intrabarordergeneration=true]

Inputs:
TCLen(10),
MA1(23),
MA2(50),
Trigger_Long (99.75),
Trigger_Short (0.25);

Variables:
MP(0);//MP = marketposition

//Value1
Value1 = (_SchaffTC(TCLen,MA1,MA2));


//Long Entry
If MP=0 and Value1 > Trigger_Long then Begin Buy ( "LE" )next bar at market;
MP = 1;
End;

//Long Exit
If MP =1 and Value1 < Trigger_Long then Begin Sell ( "LX" )next bar at market;
MP = 0;
End;


//Short Entry
If MP = 0 and Value1 < Trigger_Short then Begin Sellshort ( "SE" )next bar at market;
MP = -1;
End;

//Short Exit
If MP = -1 and Value1 > Trigger_Short then Begin Buy to Cover ( "SX" )next bar at market;
MP = 0;
End;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Quantum physics & Trading dynamics
The Elite Circle
MC PL editor upgrade
MultiCharts
ZombieSqueeze
Platforms and Indicators
What broker to use for trading palladium futures
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
24 thanks
What is Markets Chat (markets.chat) real-time trading ro …
19 thanks
ApexTraderFunding.com experience and review
17 thanks
GFIs1 1 DAX trade per day journal
13 thanks
EG Indicators
11 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


Donovan2580,

you are using intrabar order generation in your signal, so as soon as a condition is met during the bar an entry can take place. The indicator might plot at that moment, too, but remove the plot again when the conditions are not longer satisfied. This can for example explain differences. Another reason could be that the Max Bars back that you set in the signal is different than in the indicator and therefore the values are slightly different.

How "late" are some of the exits and entries? Can you show some examples of where they occur versus where they should occur? Is it possible that the order gets triggered at the end of the bar and simply executed on the next bar while the indicator already plots on the trigger bar?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
Donovan2580
Port St. Lucie, FL
 
Posts: 36 since Jul 2016
Thanks Given: 22
Thanks Received: 37

Thanks very much for the reply...

I removed the intrabarordergeneration and it worked perfectly.

You saved me a lot of time and stress!!

Much appreciated,

Donovan

Reply With Quote
Thanked by:
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Donovan,

I am glad to hear that.
You are welcome and thanks for letting me know.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #6 (permalink)
 
FastNCurious's Avatar
 FastNCurious 
saint louis MO
 
Experience: Intermediate
Platform: TradeStation
Trading: NQ, ES, YM, CL, GC
Posts: 149 since Oct 2017
Thanks Given: 95
Thanks Received: 177

I have an entry I am trying to put together and I can't get easy language to verify. I would like to get an indicator (RSI) and a show me (Supertrend) working together to screen an entry on my chart. What am I missing?


 
Code
input: 
	Length( 14 ) [DisplayName = "Length", ToolTip = 
	 "Enter the number of bars used in calculating the Volatitlity value.",
	 
	ATR_Multiplier( 2 ), ATR_Period( 3 ), Median_Period( 3 ), SingleDot( True ), 
	UpColor( Blue ), DnColor( Red ); 
	
	
variables:
	Volty( 0 ),
		
	RS( false ), MyATR( 0 ),  avg( 0 ),  dn( 0 ),  up( 0 ),  trend( 1 ),  flag( 0 ),
		flagh( 0 ),  SupTrend( 0 ),;
	
	Volty = Volatility( Length );
	RSIValue = RSI( Price, Length );
	once RS = GetAppInfo(aiApplicationType) = 2;   
	MyATR = AvgTrueRange(ATR_Period) * ATR_Multiplier;  
	avg = Average(MedianPrice,Median_Period); 
	up = avg + MyATR;  
	dn = avg - MyATR;  
 
	if close > up[1] then trend = 1  
	else if close < dn[1] then trend = -1;  
 
	if trend < 0 and trend[1] > 0 then flag=1 else flag=0;  
	if trend > 0 and trend[1] < 0 then flagh = 1 else flagh = 0;  
	if trend > 0 and dn < dn[1] then dn=dn[1];  
	if trend < 0 and up > up[1] then up=up[1];  
	if flag = 1 then up = avg + MyATR;  
	if flagh = 1 then dn = avg - MyATR;   
	if trend = 1 then SupTrend = dn else SupTrend = up;
	
If volty > 0.196 then begin

 
	If trend[1] = 1 and trend = -1 
	Sellshort next bar at market; end;

Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
FastNCurious's Avatar
 FastNCurious 
saint louis MO
 
Experience: Intermediate
Platform: TradeStation
Trading: NQ, ES, YM, CL, GC
Posts: 149 since Oct 2017
Thanks Given: 95
Thanks Received: 177

After doing some research I found that I was trying to put two indicators in one strategy when all I had to do is use the function for volatility. I think I answered my own question


Sent using the NexusFi mobile app

Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
 
FastNCurious's Avatar
 FastNCurious 
saint louis MO
 
Experience: Intermediate
Platform: TradeStation
Trading: NQ, ES, YM, CL, GC
Posts: 149 since Oct 2017
Thanks Given: 95
Thanks Received: 177

I have another code I'm trying to work out and any help would be greatly appreciated. Basically I want an algo to use Macd to generate a buy or sell signal if another condition is true. Here is my code but nothing is happening when I run the strategy. My other condition is a simple moving average slope up or down. Please help.

 
Code
inputs:  
	FastLength( 12 ) [DisplayName = "FastLength", ToolTip = 
	 "Enter number of bars to use in calculation of shorter length moving average."], 
	SlowLength( 26 ) [DisplayName = "SlowLength", ToolTip = 
	 "Enter number of bars to use in calculation of longer length moving average."], 
	MACDLength( 9 ) [DisplayName = "MACDLength", ToolTip = 
	 "Moving Average Convergence Divergence Length.  Enter the number of bars to use in smoothing the MACD value."];
	
variables:  
	MyMACD( 0 ), 
	MACDAvg( 0 ), 
	MACDDiff( 0 );

MyMACD = MACD( Close, FastLength, SlowLength );
MACDAvg = XAverage( MyMACD, MACDLength );
MACDDiff = MyMACD - MACDAvg;



if  MACDDiff < 0 and other condition then 
buy next bar market;
if  MACDDiff > 0 and other condition then 
sellshort next bar market;

Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

jburke75,

the problem might be located within your "other condition" logic as the snippet you posted appears to be correct.
Maybe you can post the full working code as this way someone might be able to steer you in the right direction.

Regards,

ABCTG


jburke75 View Post
I have another code I'm trying to work out and any help would be greatly appreciated. Basically I want an algo to use Macd to generate a buy or sell signal if another condition is true. Here is my code but nothing is happening when I run the strategy. My other condition is a simple moving average slope up or down. Please help.

 
Code
inputs:  
	FastLength( 12 ) [DisplayName = "FastLength", ToolTip = 
	 "Enter number of bars to use in calculation of shorter length moving average."], 
	SlowLength( 26 ) [DisplayName = "SlowLength", ToolTip = 
	 "Enter number of bars to use in calculation of longer length moving average."], 
	MACDLength( 9 ) [DisplayName = "MACDLength", ToolTip = 
	 "Moving Average Convergence Divergence Length.  Enter the number of bars to use in smoothing the MACD value."];
	
variables:  
	MyMACD( 0 ), 
	MACDAvg( 0 ), 
	MACDDiff( 0 );

MyMACD = MACD( Close, FastLength, SlowLength );
MACDAvg = XAverage( MyMACD, MACDLength );
MACDDiff = MyMACD - MACDAvg;



if  MACDDiff < 0 and other condition then 
buy next bar market;
if  MACDDiff > 0 and other condition then 
sellshort next bar market;


Follow me on Twitter Reply With Quote
Thanked by:
  #10 (permalink)
 
FastNCurious's Avatar
 FastNCurious 
saint louis MO
 
Experience: Intermediate
Platform: TradeStation
Trading: NQ, ES, YM, CL, GC
Posts: 149 since Oct 2017
Thanks Given: 95
Thanks Received: 177



ABCTG View Post
jburke75,

the problem might be located within your "other condition" logic as the snippet you posted appears to be correct.
Maybe you can post the full working code as this way someone might be able to steer you in the right direction.

Regards,

ABCTG

After messing around with it I found out that it was simply the Max Bars Back setting that was causing trouble. thank you for the quick response.

Visit my NexusFi Trade Journal Reply With Quote




Last Updated on March 13, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts