NexusFi: Find Your Edge


Home Menu

 





FXCorrelator


Discussion in NinjaTrader

Updated
    1. trending_up 8,036 views
    2. thumb_up 8 thanks given
    3. group 4 followers
    1. forum 20 posts
    2. attach_file 5 attachments




 
Search this Thread

FXCorrelator

  #11 (permalink)
 danjuma 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
Posts: 98 since Nov 2011
Thanks Given: 47
Thanks Received: 16

@fctrader

Sir thank you most kindly. It's a start. I would not have been able to do this myself in a million years
I have loaded it onto NT and currently monitoring it. Will report back. Much obliged.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
23 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #12 (permalink)
 fctrader 
Fort Collins, Colorado
 
Experience: Intermediate
Platform: NT7
Trading: ES
Posts: 57 since Feb 2011
Thanks Given: 48
Thanks Received: 45

Danjuma,
Your welcome. A few important things to note.

My version is based on percent difference from the prior day SMA. I think that his was based on absolute difference in the pairs other than JPY. To be truthful, I didn't reverse engineer his code entirely, since I'm not really a programmer. I just wrote the concept of it as I saw it into this code, so I hope that it is still useful to you. If you want to remove that difference, you can get rid of the "/SMA(Closes[1],MovAvgLength)[0];" from each of the deltaPair lines. I found it more useful as relative percentage changes though.

You can easily change the colors of the various pairs to your liking when you are using the indicator by double clicking any line on it, and adjusting the indicator details on the right. For my eye, I also found it useful to change the size of a pair of lines vs the rest. They are all defaulted to line size 1, but making the pairs you're focused on size 4 is helpful.

Cheers,

FCtrader

Visit my NexusFi Trade Journal Reply With Quote
  #13 (permalink)
 danjuma 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
Posts: 98 since Nov 2011
Thanks Given: 47
Thanks Received: 16


@fctrader

A bit of feedback. Firstly, thank you so much for coding this. I monitored it today against the original MT4 version. Set them up as as per the original author's method (two charts, one on 80 SMA and one on 20 SMA), using 15min bars. They do look similar, but with some small differences. I have attached a couple of images. below (the MT4 version on the left, and your version on the right). In the first image, the two main currencies that has to be monitored for the purpose of the method (the USD in green, and YEN in yellow) are both below zero on the 80 sma and 20 sma on the MT4 version. However, on your version the YEN is still above zero. though approaching/touching it. So, like I mentioned before, yours is quite close to the MT4 version, just some small differences like may be when some currencies are well below zero on the MT4 version, they might just be touching or still slightly above zero on yours. Or they might be say below zero in both versions, but starting to point upwards towards the zero direction on the MT4 version, while still pointing downwards on yours, if you know what I mean.

Not withstanding, many thanks for doing this anyway, and if you do decide to tweak it more, then I would be most grateful In the meantime, I will keep monitoring it, along with the MT4 version, and hope eventually Sir FT might be able to find the time to come up with his version.

Attached Thumbnails
Click image for larger version

Name:	FXC.jpg
Views:	119
Size:	307.7 KB
ID:	64362   Click image for larger version

Name:	FXC2.jpg
Views:	104
Size:	305.3 KB
ID:	64363  
Started this thread Reply With Quote
  #14 (permalink)
 fctrader 
Fort Collins, Colorado
 
Experience: Intermediate
Platform: NT7
Trading: ES
Posts: 57 since Feb 2011
Thanks Given: 48
Thanks Received: 45

Hi Danjuma,

I didn't get a chance to see your reply until today, as I don't get on the forum here everyday. Thank you for posting the two indicators side by side. As I hopefully made clear above, they do not do the same thing. Mine was based on percent change, while the original was based on absolute change in currency values.

My primary goal was to give you a starting point for coding a multi-symbol indicator. When I wrote it closer to the original, I saw some inconsistency in the data that indicated that a pair was diverging when the naked eye showed it to be converging. This may have been my flaw in transposing, or a flaw in the design; probably the former.

I would encourage you to tinker with the math formulas to get the result that you want. I tried to make the labels easy to read by removing "A", "B", etc and adding pair names to the formula to make it easy to edit it.

Good luck with it. Any questions posed about specific formula changes will likely get answered here by someone with better market/math/programming skills than me, but I'll try if I can!

FC

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #15 (permalink)
 fctrader 
Fort Collins, Colorado
 
Experience: Intermediate
Platform: NT7
Trading: ES
Posts: 57 since Feb 2011
Thanks Given: 48
Thanks Received: 45

@danjuma

I looked at it again and modified the necessary parts. Try this side by side, and see if it is closer to what you are expecting. The relevant parts have been commented out and rewritten below.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
    /// <summary>
    /// Replicates the FX Correlator from FXCorrelator.com
    /// </summary>
    [Description("Replicates the FX Correlator from FXCorrelator.com")]
    public class FXcorrelator : Indicator
    {
        #region Variables
        // Wizard generated variables
            private int movAvgLength = 20; // Default setting for MovAvgLength
			private double deltaEURUSD;
			private double deltaGBPUSD;
			private double deltaAUDUSD;
			private double deltaUSDCHF;
			private double deltaUSDJPY;
			private double deltaNZDUSD;
			private double deltaUSDCAD;
			private double USD_strength;
			private double EUR_strength;
			private double GBP_strength;
			private double AUD_strength;
			private double CHF_strength;
			private double JPY_strength;
			private double NZD_strength;
			private double CAD_strength;
		
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
        {
            Add("$EURUSD",BarsPeriod.Id,BarsPeriod.Value);
			Add("$GBPUSD",BarsPeriod.Id,BarsPeriod.Value);
			Add("$AUDUSD",BarsPeriod.Id,BarsPeriod.Value);
			Add("$USDCHF",BarsPeriod.Id,BarsPeriod.Value);
			Add("$USDJPY",BarsPeriod.Id,BarsPeriod.Value);
			Add("$NZDUSD",BarsPeriod.Id,BarsPeriod.Value);
			Add("$USDCAD",BarsPeriod.Id,BarsPeriod.Value);
			Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "USD"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "EUR"));
            Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "GBP"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Cyan), PlotStyle.Line, "CAD"));
			Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "CHF"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "JPY"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Pink), PlotStyle.Line, "NZD"));
            Add(new Plot(Color.FromKnownColor(KnownColor.Firebrick), PlotStyle.Line, "AUD"));
			
            Add(new Line(Color.FromKnownColor(KnownColor.Black), 0, "ZeroLine"));
            Overlay				= false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            
			if(CurrentBar==0){return;}
			//deltaEURUSD = 100*(SMA(Closes[1],MovAvgLength)[0]-SMA(Closes[1],MovAvgLength)[1])/SMA(Closes[1],MovAvgLength)[0];
			//deltaGBPUSD = 100*(SMA(Closes[2],MovAvgLength)[0]-SMA(Closes[2],MovAvgLength)[1])/SMA(Closes[2],MovAvgLength)[0];
			//deltaAUDUSD = 100*(SMA(Closes[3],MovAvgLength)[0]-SMA(Closes[3],MovAvgLength)[1])/SMA(Closes[3],MovAvgLength)[0];
			//deltaUSDCHF = 100*(-(SMA(Closes[4],MovAvgLength)[0]-SMA(Closes[4],MovAvgLength)[1]))/SMA(Closes[4],MovAvgLength)[0];
			//deltaUSDJPY = 100*(-(SMA(Closes[5],MovAvgLength)[0]-SMA(Closes[5],MovAvgLength)[1]))/SMA(Closes[5],MovAvgLength)[0];
			//deltaNZDUSD = 100*(SMA(Closes[6],MovAvgLength)[0]-SMA(Closes[6],MovAvgLength)[1])/SMA(Closes[6],MovAvgLength)[0];
			//deltaUSDCAD = 100*(-(SMA(Closes[7],MovAvgLength)[0]-SMA(Closes[7],MovAvgLength)[1]))/SMA(Closes[7],MovAvgLength)[0];
			
			deltaEURUSD = (WMA(Closes[1],MovAvgLength)[0]-WMA(Closes[1],MovAvgLength)[1]);
			deltaGBPUSD = (WMA(Closes[2],MovAvgLength)[0]-WMA(Closes[2],MovAvgLength)[1]);
			deltaAUDUSD = (WMA(Closes[3],MovAvgLength)[0]-WMA(Closes[3],MovAvgLength)[1]);
			deltaUSDCHF = (-(WMA(Closes[4],MovAvgLength)[0]-WMA(Closes[4],MovAvgLength)[1]));
			deltaUSDJPY = (-(WMA(Closes[5],MovAvgLength)[0]-WMA(Closes[5],MovAvgLength)[1]))/100;
			deltaNZDUSD = (WMA(Closes[6],MovAvgLength)[0]-WMA(Closes[6],MovAvgLength)[1]);
			deltaUSDCAD = (-(WMA(Closes[7],MovAvgLength)[0]-WMA(Closes[7],MovAvgLength)[1]));
			
			USD_strength = -(deltaEURUSD+deltaGBPUSD+deltaAUDUSD+deltaNZDUSD+deltaUSDCAD+deltaUSDJPY+deltaUSDCHF)/7;
			EUR_strength = deltaEURUSD-(deltaGBPUSD+deltaAUDUSD+deltaNZDUSD+deltaUSDCAD+deltaUSDJPY+deltaUSDCHF)/6;
			GBP_strength = deltaGBPUSD-(deltaEURUSD+deltaAUDUSD+deltaNZDUSD+deltaUSDCAD+deltaUSDJPY+deltaUSDCHF)/6;
			AUD_strength = deltaAUDUSD-(deltaEURUSD+deltaGBPUSD+deltaNZDUSD+deltaUSDCAD+deltaUSDJPY+deltaUSDCHF)/6;
			CHF_strength = deltaUSDCHF-(deltaEURUSD+deltaAUDUSD+deltaNZDUSD+deltaUSDCAD+deltaUSDJPY+deltaGBPUSD)/6;
			JPY_strength = deltaUSDJPY-(deltaEURUSD+deltaAUDUSD+deltaNZDUSD+deltaUSDCAD+deltaGBPUSD+deltaUSDCHF)/6;
			NZD_strength = deltaNZDUSD-(deltaEURUSD+deltaAUDUSD+deltaGBPUSD+deltaUSDCAD+deltaUSDJPY+deltaUSDCHF)/6;
			CAD_strength = deltaUSDCAD-(deltaEURUSD+deltaAUDUSD+deltaNZDUSD+deltaGBPUSD+deltaUSDJPY+deltaUSDCHF)/6;
			//USD_strength = deltaEURUSD;
			
            USD.Set(USD_strength);
            EUR.Set(EUR_strength);
            GBP.Set(GBP_strength);
            CAD.Set(CAD_strength);
			CHF.Set(CHF_strength);
            JPY.Set(JPY_strength);
            NZD.Set(NZD_strength);
            AUD.Set(AUD_strength);
        }
Let me know how it works out.

FC

Visit my NexusFi Trade Journal Reply With Quote
  #16 (permalink)
 fctrader 
Fort Collins, Colorado
 
Experience: Intermediate
Platform: NT7
Trading: ES
Posts: 57 since Feb 2011
Thanks Given: 48
Thanks Received: 45

If you don't want to recopy it all, the relevant part is this.

 
Code
deltaEURUSD = (WMA(Closes[1],MovAvgLength)[0]-WMA(Closes[1],MovAvgLength)[1]);
			deltaGBPUSD = (WMA(Closes[2],MovAvgLength)[0]-WMA(Closes[2],MovAvgLength)[1]);
			deltaAUDUSD = (WMA(Closes[3],MovAvgLength)[0]-WMA(Closes[3],MovAvgLength)[1]);
			deltaUSDCHF = (-(WMA(Closes[4],MovAvgLength)[0]-WMA(Closes[4],MovAvgLength)[1]));
			deltaUSDJPY = (-(WMA(Closes[5],MovAvgLength)[0]-WMA(Closes[5],MovAvgLength)[1]))/100;
			deltaNZDUSD = (WMA(Closes[6],MovAvgLength)[0]-WMA(Closes[6],MovAvgLength)[1]);
			deltaUSDCAD = (-(WMA(Closes[7],MovAvgLength)[0]-WMA(Closes[7],MovAvgLength)[1]));
just comment out the original "deltaPAIR" section, and add in the code above. Should work closer to your expectations. (I think )

Visit my NexusFi Trade Journal Reply With Quote
  #17 (permalink)
 danjuma 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
Posts: 98 since Nov 2011
Thanks Given: 47
Thanks Received: 16

@fctrader

Many thanks for doing this. Will try it out tomorrow and feed back. Most grateful.

Dan

Started this thread Reply With Quote
  #18 (permalink)
 danjuma 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
Posts: 98 since Nov 2011
Thanks Given: 47
Thanks Received: 16

Hello fctrader,

Just tried the new code on a 5min chart this morning. It's better and near identical to the MT4 version. I have attached a couple of images. A hundred thanks to you for doing this, much appreciated.

Attached Thumbnails
Click image for larger version

Name:	fxcor.jpg
Views:	117
Size:	286.2 KB
ID:	65674   Click image for larger version

Name:	fxcor2.jpg
Views:	105
Size:	284.1 KB
ID:	65675  
Started this thread Reply With Quote
  #19 (permalink)
 fctrader 
Fort Collins, Colorado
 
Experience: Intermediate
Platform: NT7
Trading: ES
Posts: 57 since Feb 2011
Thanks Given: 48
Thanks Received: 45

Thanks for posting the pictures.

The differences are interesting. I wonder if it has to do with the way the WMA is calculated between NinjaTrader and MetaTrader. In his code he used "MODE_LWMA" for Linear Weighted Moving Average, whereas I used NinjaTrader's "WMA" for Weighted Moving Average. As far as I know, they should be calculated the same, but I don't have the formulas that they used in front of me.

It could also be the data is slightly different. Are you using the same data-feed for both indicators? Or is one from your brokerage, and the other from a feed? The inter-bank market has no centralized exchange, and different providers frequently quote different numbers. If that is the case, it could easily explain the discrepancy.

Anyway, it's pretty close, and I'm glad it seems to work for you. Hopefully you can make it into a profitable system ;-)

FC

Visit my NexusFi Trade Journal Reply With Quote
  #20 (permalink)
 danjuma 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, IB TWS
Broker: IB, Kinetic
Trading: Stocks, Forex
Posts: 98 since Nov 2011
Thanks Given: 47
Thanks Received: 16


Hello fctrader, and thanks for your reply.

"Are you using the same data-feed for both indicators? Or is one from your brokerage, and the other from a feed?"

No, I am using different data-feed. The one for the MT4 is from a demo account with Alpari UK, and the one for NT is from IB.

"Anyway, it's pretty close, and I'm glad it seems to work for you. Hopefully you can make it into a profitable system"

Yes, it is very very close, and thanks for your hard work. I also hope I am able to make it into a profitable system indeed.

Started this thread Reply With Quote




Last Updated on March 9, 2012


© 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