How to code "if price increases by 5 pips"

Created at 18 Oct 2014, 22:40
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
97

9718853

Joined 14.10.2014

How to code "if price increases by 5 pips"
18 Oct 2014, 22:40


Evening all,

Can anyone please tell me how to code this phrase; "if price moves up by 5 pips 'buy'"

I've only ever had to code trade entry signals generated by indicators so far... This seems really simple but I'm stumped!

Any help would be greatly appreciated...


@9718853
Replies

9718853
18 Oct 2014, 23:15

I'm actually trying to make the robot below, simple stuff but I'm new to coding... Any advice would be much appreciated..

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class HedgeBot : Robot
    {
        [Parameter("Initial Volume", DefaultValue = 100000, MinValue = 0)]
        public int InitialVolume { get; set; }

        [Parameter("Take Profit", DefaultValue = 50)]
        public int TakeProfit { get; set; }
        
        [Parameter("Stop Loss", DefaultValue = 20)]
        public int StopLoss { get; set; }        

        private const string label = "HedgeBot";

        protected override void OnStart()
        {
            ExecuteMarketOrder(InitialVolume, TradeType.Sell);
            ExecuteMarketOrder(InitialVolume, TradeType.Buy);
        }   
                      
        protected override void Ontick()
        { 
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);
            { 
                if (Longposition.GrossProfit > 10);
        }
            ExecuteMarketOrder(TradeType.Buy, Symbol, InitialVolume * 2);    
            }
                else if (Shortposition.GrossProfit > 10);
            {
                ExecuteMarketOrder (TradeType.Sell, Symbol, InitialVolume * 2);
            }
        }
            ExecuteMarketOrder(tradeType, Symbol, volume, StopLoss, TakeProfit);
            }   
        }
    }
}

Thank you in advance, Ian


@9718853