Counter Trade free

by modarkat in category Other at 27/05/2014
Description

cBot that automatically opens a counter trade as soon as an original trade is opened.

        private const string Label = "CounterTrade";

        protected override void OnStart()
        {
            Positions.Opened += OnPositionsOpened;
        }

        void OnPositionsOpened(PositionOpenedEventArgs args)
        {
            var originalPosition = args.Position;
            if (originalPosition.Label != Label)
            {
                var tradeType = originalPosition.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;
                ExecuteMarketOrder(tradeType, Symbol, originalPosition.Volume, Label);
            }
        }

 

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 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 CounterTrade : Robot
    {
        private const string Label = "CounterTrade";

        protected override void OnStart()
        {
            Positions.Opened += OnPositionsOpened;
        }

        void OnPositionsOpened(PositionOpenedEventArgs args)
        {
            var originalPosition = args.Position;
            if (originalPosition.Label != Label)
            {
                var tradeType = originalPosition.TradeType == TradeType.Buy ? TradeType.Sell : TradeType.Buy;
                ExecuteMarketOrder(tradeType, Symbol, originalPosition.Volume, Label);
            }
        }
    }
}
Comments

aysos75 - July 17, 2014 @ 11:50

Il y a une erreur dans le code :

remplacer 

originalPosition.Label != Label

par

originalPosition.Label == Label

aysos75 - July 17, 2014 @ 11:53

Sorry there is no error

davidp13 - March 25, 2015 @ 13:51

Hi, how can I add this code to a robot that opens trades onBar. I have tried to add it, but it opens not counter trades. Thanks

Gwave - March 21, 2018 @ 17:14

Hi guys.

How can i modify CounterTrade to automatically Close " it's trade " when the " Original position " closes. Please, any help would be much appreciated. 

Many Thanks

hankfreid - May 27, 2022 @ 14:05

Knowledge4Sure's AZ-303 dumps contain questions and replies on the main sections of AZ-303 certificate prospectus. These inquiries are generally rehashed in the genuine Azure Solutions Architect Expert test and subsequently they have a gigantic significance for test competitors. Setting up these AZ-303 inquiries improve your advancing as well as augment your score.

By offering you its AZ-303 Testing Engine office, Knowledge4Sure offers you a one of a kind chance to encounter the genuine Microsoft Azure Architect Technologies test situation. The Testing Engine gives you various test like AZ-303 practice tests, involving generally the inquiries taken from the old papers of Microsoft AZ-303 accreditation test. By addressing these tests you not just know the arrangement of the real Azure Solutions Architect Expert AZ-303 Dumps Questions yet additionally become familiar with your shortcomings. In this way, you can without much of a stretch further develop your Azure Solutions Architect Expert learning and light up your odds of coming out on top.

jamesjon4050 - November 21, 2022 @ 11:40

Valid4sure offer Cisco 200-201 Exam Dumps Question with comprehensive and detailed material, which covers the entire syllabus recommended by Cisco. Here you can find all the free questions related to Understanding Cisco Cybersecurity Operations Fundamentals Exam

3.33