problem with API class and their position

Created at 14 Oct 2012, 14:38
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!
BA

banbeng

Joined 30.09.2012

problem with API class and their position
14 Oct 2012, 14:38


I am creating a program that uses

"Symbol.PipSize"

"Account.Positions "

 

but does not appear certain times in the list!!

 

public class Imperial : Robot

OnStart / OnTick / OnStop   ex: protected override void OnStart()

this api can be used

 

If i have created 1 other class and i wont use a api --> does NOT work ( and I get the error that the api do not exist in that context)

  public class Opertation //(the 2°)

                public int ord_pn() 

 

and this api can't be used

 

can you give me an example of program

with more classes A-B-C and class B within a management treiling or placing an order which will be called in the main class A!

 

 


@banbeng
Replies

admin
15 Oct 2012, 09:57

Hello,

 

In cAlgo you need to define each class in a separate file. Then you need to reference that file in the class which you want to use it. The filenames should be the same as the classes defined in them, i.e. class Imperial should be saved in filename Imperial.cs

e.g. 

//#reference: ..\Robots\Opertation.algo

using cAlgo.API;

namespace cAlgo.Robots
{
    public class Imperial : Robot
    {
        private Opertation robot;

        // etc.

    }
}

 

 

 


@admin

banbeng
16 Oct 2012, 01:09

RE:
admin said:

Hello,

 

In cAlgo you need to define each class in a separate file. Then you need to reference that file in the class which you want to use it. The filenames should be the same as the classes defined in them, i.e. class Imperial should be saved in filename Imperial.cs

e.g. 

//#reference: ..\Robots\Opertation.algo

using cAlgo.API;

namespace cAlgo.Robots
{
    public class Imperial : Robot
    {
        private Opertation robot;

        // etc.

    }
}

 

 

 

I placed the code
creating two new classes
which I compiled
and called up
 
/ / # reference: .. \ Robots \ HD.algo
/ / # reference: .. \ Robots \ Tool.algo
 
but one of them gave me a problem in compiling:
 
build succeeded
Unable to load assembly: assembly must contain single algo type
 
 

@banbeng

admin
16 Oct 2012, 10:16

RE: RE:
banbeng said:
admin said:

Hello,

 

In cAlgo you need to define each class in a separate file. Then you need to reference that file in the class which you want to use it. The filenames should be the same as the classes defined in them, i.e. class Imperial should be saved in filename Imperial.cs

e.g. 

//#reference: ..\Robots\Opertation.algo

using cAlgo.API;

namespace cAlgo.Robots
{
    public class Imperial : Robot
    {
        private Opertation robot;

        // etc.

    }
}

 

 

 

I placed the code
creating two new classes
which I compiled
and called up
 
/ / # reference: .. \ Robots \ HD.algo
/ / # reference: .. \ Robots \ Tool.algo
 
but one of them gave me a problem in compiling:
 
build succeeded
Unable to load assembly: assembly must contain single algo type
 
 
Is it possible to post the code for the one with the problem?
 

@admin

banbeng
16 Oct 2012, 22:18

// -------------------------------------------------------------------------------
//
//    This is a Template used as a guideline to build your own Robot. 
//    Please use the “Feedback” tab to provide us with your suggestions about cAlgo’s API.
//
// -------------------------------------------------------------------------------



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


namespace cAlgo.Robots
{
	
    public class Tool
    {
    	//public Position pos;
    	
    	//Info informazione=new Info();
    	int decimali=0;
    	
    	
    	public Tool(int decimalii)
    	{
    		this.decimali=decimalii;
    	
    	}
    	
    	 //arrotonda//
    	 //arrotonda//
    	public double round(int dir, double cos , double pipsize)
    	{
    		double norm,ln=0;
    		if(decimali!=-1){ ln=Math.Round(cos,decimali);}
    		else { Console.WriteLine("Error");}
    		if(dir==-1)
    		{
    			if(ln<cos){norm=ln;} if(ln="=cos){norm=ln;}">cos){norm=ln-1* pipsize;}
    		}
    		
    		if(dir==1)
    		{
    			if(ln<cos){norm=ln+1* pipsize;}="" if(ln="=cos){norm=ln;}">cos){norm=ln;}
    			//Trade.CreateSellStopOrder(Symbol,1000,Symbol.Bid,null,null,null);
    		}
    		return ln;
    	}
    	
    
    
    }
    
 }   
   

 


@banbeng

banbeng
16 Oct 2012, 22:25

(this is the code thet give me the error!)

 

in the if the true code are:

 

if(ln<cos){norm=ln;}
 if(ln==cos){norm=ln;}
if(ln>cos){norm=ln-1* pipsize;}

 

must be badly enter the code in the last reply


@banbeng

admin
17 Oct 2012, 12:22

If you are going to use namespace cAlgo.Robot

Then you need to define your class as Robot

i.e.

    [Robot]
    public class Tool:Robot

 

Other than that I see a few issues with the code but no syntax error, like norm is a local variable being assigned but not used.

So the code starting from if(dir == -1) ... (until right before) return ln;

is essentially useless.

Also note that ln-1*pipsize is equal to ln-pipsize as well as ln+1* pipsize is equal to ln+pipsize

I presume that what you need is  (ln-1)*pipsize and (ln+1)* pipsize


@admin

banbeng
18 Oct 2012, 12:15

RE:
thanks both for  response that for advice on the code

Robot class creates conflicts when
call objects in my main?

I can then use the robot class to class without any problems?
I thought it was unique ability of the main class.

@banbeng

admin
18 Oct 2012, 14:15

RE: RE:
banbeng said:
thanks both for  response that for advice on the code

Robot class creates conflicts when
call objects in my main?

I can then use the robot class to class without any problems?
I thought it was unique ability of the main class.
I'm not sure what you mean. It seems like a c# question. If so, please visit msdn http://msdn.microsoft.com/en-us/default.aspxOtherwise, please clarify.
 
Regards.
 
 
 

@admin