ArtificialIntelligence free

by qualitiedx2 in category Other at 16/03/2012
Description
The Artificial Intelligence robot creates trades based on the result of the previous ones. It uses the MACD Indicator to calculate the direction of the trade the first time and then continues based on this as well as the outcome of the closed positions.
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 cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class ArtificialIntelligence : Robot
    {
        [Parameter("x1",DefaultValue=281)]
        public int x1 { get; set; }
        
        [Parameter("x2",DefaultValue=100)]
        public int x2 { get; set; }

        [Parameter("x3",DefaultValue=794)]
        public int x3 { get; set; }
        
        [Parameter("x4",DefaultValue=566)]
        public int x4 { get; set; }
        
        [Parameter("FastMA",DefaultValue=20)]
        public int FastMA { get; set; }
        
        [Parameter("SlowMA",DefaultValue=21)]
        public int SlowMA { get; set; }
        
        [Parameter("Step",DefaultValue=28)]
        public int Step { get; set; }
        
        [Parameter("StopLoss",DefaultValue=550)]
        public int StopLoss { get; set; }
        
        [Parameter("Volume",DefaultValue=10000)]
        public int Volume { get; set; }
        
        private MacdHistogram macd;
        private Position pos;
        private bool IsPosOpen=false;
        private double sl;
        protected override void OnStart()
        {
            macd=Indicators.MacdHistogram(SlowMA,FastMA,3);
        }

        protected override void OnTick()
        {
            int last=MarketSeries.Close.Count-1;
            if(!(MarketSeries.Open[last]==MarketSeries.High[last] && MarketSeries.Open[last]==MarketSeries.Low[last])) return;
            double per=percertron();
            if(!IsPosOpen)
            {
 				if(per>0) {Trade.CreateBuyMarketOrder(Symbol,Volume); IsPosOpen=true;}
 				if(per<0) {Trade.CreateSellMarketOrder(Symbol,Volume); IsPosOpen=true;}
            }
            else
            {
            	if(pos.TradeType==TradeType.Buy && per<0)
            	{
            		Trade.Close(pos);
            		Trade.CreateSellMarketOrder(Symbol,Volume);
            		return;
            	}
            	else
            	{
            		if(Symbol.Ask>sl+StopLoss*2*Symbol.PointSize) Trade.ModifyPosition(pos,Symbol.Ask-StopLoss*Symbol.PointSize,0);
            	}
            	if(pos.TradeType==TradeType.Sell && per>0)
            	{
            		Trade.Close(pos);
            		Trade.CreateBuyMarketOrder(Symbol,Volume);
            	}
            	else
            	{
            		if(Symbol.Bid<sl-StopLoss*2*Symbol.PointSize) Trade.ModifyPosition(pos,Symbol.Bid+StopLoss*Symbol.PointSize,0);
            	}
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
        
        protected override void OnPositionOpened(Position openedPosition)
        {
            pos=openedPosition;
            if(openedPosition.TradeType==TradeType.Buy)
            {
            	sl=Symbol.Ask-StopLoss*Symbol.PointSize;
            	Trade.ModifyPosition(openedPosition,sl,0);
           	}
            if(openedPosition.TradeType==TradeType.Sell)
            {
            	sl=Symbol.Bid+StopLoss*Symbol.PointSize;
            	Trade.ModifyPosition(openedPosition,sl,0);
           	}
        }
        
        private double percertron()
        {
        	int last=MarketSeries.Close.Count-1;
        	double w1=x1-100;
        	double w2=x2-100;
        	double w3=x3-100;
        	double w4=x4-100;
        	double a1=macd.Histogram[last-1];
        	double a2=macd.Histogram[last-1-Step];
        	double a3=macd.Histogram[last-1-Step*2];
        	double a4=macd.Histogram[last-1-Step*3];
        	return w1*a1+w2*a2+w3*a3+w4*a4;
        }
    }
}
Comments

Anonymous - October 08, 2012 @ 17:39

thanks

anteandrovic - October 23, 2012 @ 12:25

... any body have some recommended settings for this code ?

anteandrovic - November 02, 2012 @ 10:47

Any sample setting s recommended ? What is the meaning of the inputs x1 x2 x3 x4 ? .... + "step" ? Regards, aa

WhiteSage - September 14, 2014 @ 22:12

Best settings are usually found with a 'brute force' backtesting system not found in cAlgo

WhiteSage - October 05, 2014 @ 06:34

Turns out the beta now has optimization, one should be able to tune this example with it.

aimerdoux - June 28, 2015 @ 18:42

you can Actually change the optimization method by clicking in the icon GA and choosing the other option of optimization.

sulemankm - April 08, 2016 @ 17:42

Any performance results plz? Backtest, demo account results, anything?

 

mardahl - May 04, 2016 @ 14:16

I see you're trying to make a neural network with one perceptron.
To maintain proper learning process you could use backpropagation algorithm - i found this tutorial very helpful in the task: https://mattmazur.com/2015/03/17/a-step-by-step-backpropagation-example/

anthony21xu - September 19, 2018 @ 13:53

Error CS0672: Member 'cAlgo.Robots.ArtificialIntelligence.OnPositionOpened(cAlgo.API.Position)' overrides obsolete member 'cAlgo.API.Robot.OnPositionOpened(cAlgo.API.Position)'. Add the Obsolete attribute to 'cAlgo.Robots.ArtificialIntelligence.OnPositionOpened(cAlgo.API.Position)'.

 

can anyone help with this? where should i put this

0