Category Trend  Published on 28/08/2024

CSTP 2 Parametters

Description

Here’s a simple description of the C# code and its importance for the cTrader Strategy Tester v1.12 bot:  (https://ctrader.com/algos/cbots/show/4487/)

Code Description

Declaration and Parameters:

  • This code defines an indicator called CSTP_Indi_2Parametter, which allows the user to choose from several technical indicators through the IndicatorSelection parameter.
  • Two additional parameters, Value1 and Value2, are used to define specific values required for the calculations of the selected indicators.

Indicator Enumeration:

  • An enumeration (EnumIndiSelection) is defined, listing three indicators: SuperTrend, Parabolic SAR, and a custom indicator called Bars vs Vidya.

Indicator Calculations:

The Calculate(int index) method is the core of the code, executed for each new data point (each new bar). Depending on the selected indicator, it calculates values for Result (the primary value) and Signal (the calculated indicator value).

For example:

  • For SuperTrend, the code calculates the Parabolic SAR result and determines whether the trend is up or down based on the SuperTrend.
  • For Parabolic SAR, the closing price is used as the Result, and the Parabolic SAR calculation as the Signal.
  • For Bars vs Vidya, the closing price is used as Result, and the Vidya calculation as Signal.

Result Display:

  • The results of these calculations are plotted on the chart as two lines (Result and Signal), with defined colors and styles.

Importance for the cTrader Strategy Tester v1.12 Bot

This code is crucial for the cTrader Strategy Tester v1.12 bot. It enables the bot to test and optimize trading strategies based on indicators like SuperTrend, Parabolic SAR, and other trend-following techniques. With this code, the bot can adapt its strategies based on the calculated signals, which is essential for making effective trading decisions in various market conditions.

We are looking for all types of profiles interested in joining the adventure, so if you want to discuss this further, this is the place to do it : 

Telegram group : https://t.me/cTraderStrategyTesterProject

GitHub : https://github.com/YesOrNotCtrader/Ctrader-Stragegy-Tester-Project

Enjoy for Free =) 
Previous account here : https://ctrader.com/users/profile/70920
Contact telegram :  https://t.me/nimi012 

 

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class CSTP_Indi_2Parametter : Indicator
    {
        [Parameter(DefaultValue = EnumIndiSelection.SuperTrend)]
        public EnumIndiSelection IndicatorSelection { get; set; }
        public enum EnumIndiSelection
        {
            SuperTrend,
            Parabolic_Sar,
            Bars_Vs_Vidya,

        }

        [Parameter(DefaultValue = 13)]
        public double Value1 { get; set; }
        [Parameter(DefaultValue = 3)]
        public double Value2 { get; set; }

        [Output("Result", IsHistogram = false, LineColor = "Green", LineStyle = LineStyle.Solid, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Result { get; set; }
        [Output("Signal", IsHistogram = false, LineColor = "Red", LineStyle = LineStyle.Solid, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries Signal { get; set; }

        protected override void Initialize()
        {

        }
        public override void Calculate(int index)
        {
            switch (IndicatorSelection)
            {
                case (EnumIndiSelection.SuperTrend):
                    Result[index] = Indicators.ParabolicSAR((int)Value1, (int)Value2).Result[index];
                    Signal[index] = !double.IsNaN(Indicators.Supertrend((int)Value1, (int)Value2).UpTrend[index]) ? Indicators.Supertrend((int)Value1, (int)Value2).UpTrend[index] : Indicators.Supertrend((int)Value1, (int)Value2).DownTrend[index];
                    break;
                case (EnumIndiSelection.Parabolic_Sar):
                    Result[index] = Bars.ClosePrices[index];
                    Signal[index] = Indicators.ParabolicSAR((int)Value1, (int)Value2).Result[index];
                    break;
                case (EnumIndiSelection.Bars_Vs_Vidya):
                    Result[index] = Bars.ClosePrices[index];
                    Signal[index] = Indicators.Vidya(Bars.ClosePrices, (int)Value1, Value2).Result[index];
                    break;
            }
        }
    }
}


YE
YesOrNot2

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: CSTP_Indi_2Parametter.algo
  • Rating: 0
  • Installs: 287
  • Modified: 28/08/2024 15:20
Comments
Log in to add a comment.
No comments found.