Fibo free

by mh_82 in category Trend at 10/11/2022
Description

fibo cos

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
//#reference: ..\Indicators\FibonacciBands.algo
//#reference: ..\Indicators\Velocidade.algo
// -------------------------------------------------------------------------------
//
//    This is a Template used as a guideline to build your own Robot. 
//
// -------------------------------------------------------------------------------


using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Requests;
using cAlgo.Indicators;
using System.IO;
using System.Collections.Generic;

using System.Linq;
using System.Runtime.InteropServices;
using System.Globalization;


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class SR_Fibo : Robot
    {
        [Parameter(DefaultValue = 100000)]
        public int Volume { get; set; }
        [Parameter(DefaultValue = 21)]
        public int AtrPeriod { get; set; }
        [Parameter(DefaultValue = 55)]
        public int emaPeriod { get; set; }
        [Parameter(DefaultValue = 10)]
        public int velPeriod { get; set; }

        List<double> fibo;
        int idx;

        Velocidade tendencia;
        FibonacciBands fbands;

        double stop, gain, price;
        PendingOrder ordemc, ordemv;
        Position posicao;
        private void seta_variaveis(TradeType oper)
        {
            carregar_fibo();

            if (oper == TradeType.Buy)
                price = precos(fibo, Symbol.Ask, oper);
            else
                price = precos(fibo, Symbol.Bid, oper);
            stop = stopcalc(oper, fibo);
            gain = gaincalc(oper, fibo);

        }

        protected override void OnPendingOrderCreated(PendingOrder newPendingOrder)
        {
            if (newPendingOrder.TradeType == TradeType.Sell)
                ordemv = newPendingOrder;
            else
                ordemc = newPendingOrder;

        }

        protected override void OnBar()
        {
            carregar_fibo();
            Trade.DeletePendingOrder(ordemv);
            Trade.DeletePendingOrder(ordemc);

            if (tendencia.velocidade.LastValue > 0 && Functions.IsRising(tendencia.velocidade))
                abreposicoes(TradeType.Buy);
            if (tendencia.velocidade.LastValue < 0 && Functions.IsFalling(tendencia.velocidade))
                abreposicoes(TradeType.Sell);



        }
        protected override void OnStart()
        {

            tendencia = Indicators.GetIndicator<Velocidade>(MarketSeries.Close, velPeriod);
            fbands = Indicators.GetIndicator<FibonacciBands>(emaPeriod, AtrPeriod);

            fibo = new List<double>();
            carregar_fibo();
            organizarVetores();
            abreposicoes(TradeType.Buy);
            abreposicoes(TradeType.Sell);
            Print("OK!!!");
        }

        protected override void OnTick()
        {

        }
        private void organizarVetores()
        {
            fibo.Sort();
            fibo.Reverse();


        }

        private void carregar_fibo()
        {
            fibo.Clear();
            fibo.Add(fbands.UpperBand4.LastValue);
            fibo.Add(fbands.UpperBand3.LastValue);
            fibo.Add(fbands.UpperBand2.LastValue);
            fibo.Add(fbands.UpperBand1.LastValue);
            fibo.Add(fbands.LowerBand1.LastValue);
            fibo.Add(fbands.LowerBand2.LastValue);
            fibo.Add(fbands.LowerBand3.LastValue);
            fibo.Add(fbands.LowerBand4.LastValue);
        }

        private void abreposicoes(TradeType oper)
        {

            seta_variaveis(oper);
            if (oper == TradeType.Buy)
                Trade.CreateBuyLimitOrder(Symbol, Volume, price, stop, gain, null);
            if (oper == TradeType.Sell)
            {
                Trade.CreateSellLimitOrder(Symbol, Volume, price, stop, gain, null);

            }
        }

        private double stopcalc(TradeType oper, List<double> sr)
        {
            organizarVetores();
            if (oper == TradeType.Sell)
                sr.Sort();
            if (idx < sr.Count - 1 && Math.Abs(sr[idx] - Symbol.Bid) / Symbol.PipSize > 5)
                return sr[idx + 1];
            else if (oper == TradeType.Buy)
                return sr[idx] - 20 * Symbol.PipSize;
            else if (oper == TradeType.Sell)
                return sr[idx] + 20 * Symbol.PipSize;



            return 0;
        }

        private double gaincalc(TradeType oper, List<double> sr)
        {
            organizarVetores();
            if (oper == TradeType.Sell)
                sr.Sort();

            return sr[idx - 1];
        }




        private double precos(List<double> sr, double price, TradeType oper)
        {
            organizarVetores();
            if (oper == TradeType.Buy)
            {
                for (var i = 1; i < sr.Count() - 1; i++)
                {
                    if (tendencia.velocidade.LastValue > 0 && price - sr[i] > 10 * Symbol.PipSize)
                        if (sr[i] < price)
                        {
                            idx = i;
                            return sr[i];
                            break;
                        }


                    if (tendencia.velocidade.LastValue < 0 && price - sr[i] > 10 * Symbol.PipSize)
                        if (sr[i] < price)
                        {

                            idx = i + 1;
                            return sr[i + 1];
                            break;


                        }

                }

            }
            if (oper == TradeType.Sell)
            {

                sr.Sort();

                for (var i = 1; i < sr.Count() - 1; i++)
                {

                    if (tendencia.velocidade.LastValue < 0 && sr[i] - price > 10 * Symbol.PipSize)
                    {

                        if (sr[i] > price)
                        {

                            idx = i;
                            return sr[i];
                            break;
                        }
                    }
                    if (tendencia.velocidade.LastValue > 0 && sr[i] - price > 10 * Symbol.PipSize)
                        if (sr[i] > price)
                        {

                            idx = i + 1;
                            return sr[i + 1];
                            break;


                        }
                }

            }

            return 0;
        }


        protected override void OnPositionOpened(Position posicaoaberta)
        {
            posicao = posicaoaberta;
            Print("Nova posi??o aberta\n");

        }

        protected override void OnPositionClosed(Position posicaoaberta)
        {
            posicao = null;


        }
        protected override void OnStop()
        {
            Trade.DeletePendingOrder(ordemv);
            Trade.DeletePendingOrder(ordemc);
        }
    }
}
Comments

donnajane1205 - November 10, 2022 @ 11:11

I have read a lot of retro bowl articles. However, this article has distinct and very profound points. I hope to visit your other posts

dietrichvidal - November 18, 2022 @ 03:14

Many articles have been read by me. This article, however, makes some clear and profound arguments. Eventually, I'll make it over to your other threads. 
basketball stars

asshancuc - November 19, 2022 @ 04:41

I've been searching for hours on this topic and finally found your post. casino online I have read your post and I am very impressed.  We prefer your opinion and will visit this site frequently to refer to your opinion. When would you like to visit my site? 

0