Topics
18 Jun 2014, 01:54
 3171
 5
26 Mar 2014, 18:55
 8042
 13
26 Feb 2014, 19:39
 0
 2754
 2
21 Jan 2014, 20:33
 0
 2854
 2
31 Dec 2013, 03:17
 3517
 6
13 Nov 2013, 20:58
 3160
 3
15 Oct 2013, 20:13
 2818
 3
Replies

Old Account
30 May 2016, 16:58

RE: RE:

MRSV said:

marc.sischka said:

Hi all, 

The strategy creates a position onBar (daily). I want the strategy to close the position on the next bar no matter what. 

Could you please help me how I can achieve that. 

Thanks

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnBar()
        {
            if (Positions.Count != 0)
            {
                ClosePosition(Positions.Find("pos"));
            }
            
            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "pos");
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Set timeframe to daily. You didn't say if you wantet to open a buy or sell position, so I set it to open a buy position.

 


@Old Account

Old Account
21 Jul 2014, 20:57

 

This was an example of how to use the Close() method.

If(SMA.Result.LastValue > 1)

Close();

 

It is the same as the method for opening a position, but insted of opening a position it closes it.

So you have for your criteria for closing a position that is the IF("something") then close.

 

In the example i used all positions would close when the Simple Moving Average hit 1.

If you want the position to close when EMA is equal or less the the as you write it like this:

If(EMA.Result.LastValue <= Symbol.Ask)
Close();

 

 

 


@Old Account

Old Account
20 Jul 2014, 19:23

Add this to you code

private void Close()
        {
            foreach (var position in Positions)
            {
                ClosePosition(position);
            }
        }

 

And when you want to close a position add Close()

Like this:

If(SMA.Result.LastValue > 1)

Close();

Hope it helped


@Old Account

Old Account
18 Jun 2014, 15:03 ( Updated at: 21 Dec 2023, 09:20 )

RE: RE:

Spotware said:

MRSV said:

Hi

Saw this today, and wonderd if it were a chart bug or not

Found it a little hard to belive that GBPJPY jumped 3000 pips

Please specify Broker Name and Environment (live, demo).

LiquidMarkets demo account


@Old Account

Old Account
04 May 2014, 01:56

bool N_MACD = MACD.Histogram.LastValue <=0;

 


@Old Account

Old Account
25 Apr 2014, 00:25

It looks good, but it's hard to say with just one image.


@Old Account

Old Account
22 Apr 2014, 23:08

RE:

Researcher said:

If there is no such position on tick the Find() method returns null. Try this code:

     protected override void OnTick()
     {
         var position = Positions.Find("Test"); 
         if (position != null)
             ClosePosition(position);
     }

 

Thank you !!!


@Old Account

Old Account
12 Apr 2014, 01:03

Too risky for me


@Old Account

Old Account
31 Mar 2014, 14:00

I'll be happy to help too.


@Old Account

Old Account
21 Mar 2014, 20:23

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter("Fast Periods", DefaultValue = 10)]
        public int F_Periods { get; set; }

        [Parameter("Slow Periods", DefaultValue = 20)]
        public int S_Periods { get; set; }

        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        public WeightedMovingAverage F_WMA;
        public WeightedMovingAverage S_WMA;
        public bool TradeS;
        public bool TradeB;

        protected override void OnStart()
        {
            F_WMA = Indicators.WeightedMovingAverage(MarketSeries.Close, F_Periods);
            S_WMA = Indicators.WeightedMovingAverage(MarketSeries.Close, S_Periods);
        }

        protected override void OnTick()
        {
            bool isBuyPositionOpen = Positions.Count != 0 && LastResult.Position.TradeType == TradeType.Buy;
            bool isSellPositionOpen = Positions.Count != 0 && LastResult.Position.TradeType == TradeType.Sell;

            if (S_WMA.Result.LastValue > F_WMA.Result.LastValue && !isSellPositionOpen && TradeS)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "", 20, 20);
                TradeS = false;
            }

            if (S_WMA.Result.LastValue < F_WMA.Result.LastValue && !isBuyPositionOpen && TradeB)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "", 20, 20);
                TradeB = false;
            }

        }


        protected override void OnBar()
        {
            TradeS = true;
            TradeB = true;
        }
    }
}

 


@Old Account

Old Account
11 Mar 2014, 19:05

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class cAlgoForum : Robot
    {
        public int FailTradeCount;
        public int TradeCooldown;

        protected override void OnStart()
        {
            Positions.Closed += PositionsOnClosed;
            FailTradeCount = 0;
            TradeCooldown = 0;
        }

        protected override void OnTick()
        {
            double Median_P10 = MarketSeries.Median.LastValue + (10 * Symbol.PipSize);
            double Median_M10 = MarketSeries.Median.LastValue - (10 * Symbol.PipSize);

            bool Check_1 = Symbol.Spread <= 5;
            bool Check_2 = Positions.Count <= 2;
            bool Check_3 = FailTradeCount <= 0;
            bool Chech_4 = TradeCooldown <= 0;

            bool Check_5B = Symbol.Ask >= Median_P10;
            bool Check_5S = Symbol.Ask <= Median_M10;



            if (Check_1 && Check_2 && Check_3 && Chech_4 && Check_5B)
                ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "Buy", 20, 40);

            if (Check_1 && Check_2 && Check_3 && Chech_4 && Check_5S)
                ExecuteMarketOrder(TradeType.Sell, Symbol, 10000, "Sell", 20, 40);
            Print("{0}{1}", Check_5S, Check_5B);
        }
        private void PositionsOnClosed(PositionClosedEventArgs args)
        {

            var position = args.Position;

            if (position.GrossProfit < 0)
                FailTradeCount = 10;

            if (position.EntryTime == DateTime.Now)
                TradeCooldown = 2;

        }
        protected override void OnBar()
        {
            FailTradeCount = FailTradeCount - 1;
            TradeCooldown = TradeCooldown - 1;
        }
    }
}

 


@Old Account

Old Account
08 Mar 2014, 17:30

I think if I were to calculate the angle like the Ray chart tool I will need to know the scale to see the distanse in pips one hour is equal to.

Are there any ways to do that ?


@Old Account

Old Account
05 Mar 2014, 19:42

Sorry, I posted it in Indicator Development Support by mistake and i wasn't able to delete it.


@Old Account

Old Account
02 Mar 2014, 00:57

I'm not shure i understan what you are looking for, could you explane it a bit more?

 


@Old Account

Old Account
01 Mar 2014, 00:11

     protected override void OnTick()
        {
            Print(Server.Time);
        }


@Old Account

Old Account
31 Jan 2014, 11:13

Try to use this

http://2calgo.com/

 


@Old Account

Old Account
28 Jan 2014, 00:27

Well its not -7.36039, It's -0,0000736039. 

-7.36039-E05 = -7.36039*10^-5 <=> -0,0000736039.


@Old Account

Old Account
27 Jan 2014, 15:45

  Print("{0}", _macd.Histogram.LastValue);


@Old Account

Old Account
26 Jan 2014, 01:35

RE:

MrSvensli@hotmail.no *

I would be happy to help you, but i don't have much experience whit  Ichimoku so you are going to have to explainit a bit more for me. You can contact me at MrSvesli@hotmail.no if you to. 

 


@Old Account