POSITIVE correratnEURUSD, USDJPY, EURJPY free

by davidmwabuka in category Trend at 16/05/2023
Description

USING PSAR. This robot checks for positive corelation in trend between EURUSD, USDJPY, EURJPY. if they are both trending upwards then we buy because it is a strong uptrend. 

currently i used PARABORIC SAR: the current psar is below price on both at the same time EURUSD, USDJPY, EURJPY. it buys. and vice versa.

suggestions accepted.

I really need your comments they encourage me to post these bots i had beed developing and couldnt continue alone.

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class PsarBot : Robot
    {
        private readonly string[] symbolNames = { "EURUSD", "USDJPY", "EURJPY" };
        private readonly TimeFrame timeFrame = TimeFrame.Minute15;

        private MarketSeries[] symbolSeries;
        private ParabolicSAR[] parabolicSARs;

        protected override void OnStart()
        {
            symbolSeries = new MarketSeries[symbolNames.Length];
            parabolicSARs = new ParabolicSAR[symbolNames.Length];

            for (int i = 0; i < symbolNames.Length; i++)
            {
                Symbol symbol = MarketData.GetSymbol(symbolNames[i]);
                if (symbol == null)
                {
                    Print($"Error: Symbol {symbolNames[i]} does not exist");
                    continue;
                }

                symbolSeries[i] = MarketData.GetSeries(symbol, TimeFrame.Minute15);
                parabolicSARs[i] = Indicators.ParabolicSAR(symbolSeries[i], 0.02, 0.2);
            }
        }

        protected override void OnBar()
        {
            for (int i = 0; i < symbolNames.Length; i++)
            {
                Symbol symbol = MarketData.GetSymbol(symbolNames[i]);
                double psarValue = parabolicSARs[i].Result.Last(0);
                double bid = symbol.Bid;

                if (psarValue < bid)
                {
                    ExecuteMarketOrder(TradeType.Buy, symbol, 1000, "PSAR Buy", 0, 10);
                }
                else if (psarValue > bid)
                {
                    ExecuteMarketOrder(TradeType.Sell, symbol, 1000, "PSAR Sell", 0 , 10);
                }
            }
        }
    }
}
Comments

singalgolab - May 16, 2023 @ 14:53

Interesting Strategy. the same concept could be applied to Pair Trading especially EURUSD GBPUSD. For example a PSAR above EURUSD and below GBPUSD, you sell EURUSD and buy GBPUSD. maybe ill try coding this later. Cheers!

0