Replies

TraderM
10 Mar 2013, 15:35

RE:
TraderM said:

Hi,

I am having difficulty calculating Volume. I have programmed a solution for AUDUSD (x.xyzxz) (and this works for other currencies where there are 5 values after the decimal place) but this solution does not work for example with the EURJP (xzx.xyz) and USDJPY (xy.xyz).

I think I have to somehow factor in the Ask price to make the calculation valid for all currencies but I don't not know how to do this.

This is my solution (simplified) for AUDUSD, first some explanations:

- Risk is in EUR (but should also be possible for GBP, USD or whatever currency the trading account is in)

- riskInPips is calculated elsewhere, could be the size of a candle

- we have to convert from double to int

- we have to round off the lots/Volume somehow

A hardcoded version looks like this. Results are shown behind //:

                riskInPips = 0.00123;

                Risk = 500;
                
                int lots = (int)(Risk/riskInPips); //406504
                
                lots = lots/10000; lots = lots*10000; // 400000
               
                Volume = lots;
              
                Trade.CreateBuyLimitOrder(Symbol,Volume,entry,SL,TP,null);            

Does anyone know how to do this better. If possible so that it works for all currency pairs and if possible for accounts in different currencies?

I would really appreciate your advice,

Thanks,

TraderM

 

 

Hi,

I have solved this as following:

// For xxx.yyy and x.yyyyy currencies listed in setVolumeConverter()
                int lots = (int)(Risk/(riskInPips/volumeConverter));                

                lots = lots/10000; lots = lots*10000; // Round off using integer truncation
 
                Volume = lots;

The volumeConverter is set when the robot starts using this: setVolumeConverter();

The setVolumeConverter() method looks like this:

 private void setVolumeConverter()            
            {
            
            switch (Symbol.Code)
            {
             // x.yyyyy currencies  
                case "EURUSD":volumeConverter = 1;
                break;
                case "USDCAD":volumeConverter = 1;
                break;
                case "EURCAD":volumeConverter = 1;
                break;
                case "GBPCHF":volumeConverter = 1;
                break;
                case "GBPUSD":volumeConverter = 1;
                break;
                case "EURAUD":volumeConverter = 1;
                break;
                case "AUDCAD":volumeConverter = 1;
                break;
                case "EURTRY":volumeConverter = 1;
                break;
                case "AUDUSD":volumeConverter = 1;
                break;
                case "GBPAUD":volumeConverter = 1;
                break;
                case "USDSGD":volumeConverter = 1;
                break;
                case "GBPCAD":volumeConverter = 1;
                break;
                case "USDCHF":volumeConverter = 1;
                break;
                case "EURGBP":volumeConverter = 1;
                break;                 
                case "NZDUSD":volumeConverter = 1;
                break;
                // xxx.yyy currencies   
                case "EURJPY":volumeConverter = 100;
                break;
                case "GBPJPY":volumeConverter = 100;
                break;
                case "USDJPY":volumeConverter = 100;
                break;
                case "CADJPY":volumeConverter = 100;
                break;
                case "AUDJPY":volumeConverter = 100;
                break;
                }
            Print("volumeConverter: {0}", volumeConverter);
           }

This solution is not particularly elegant. Maybe someone has a better solution?

TraderM

 


@TraderM

TraderM
05 Mar 2013, 22:09

RE:
condor said:

I tried this :

        [Parameter("Use Trade Time ?", DefaultValue = false)]
        public bool UseTradeTime { get; set; }

I got a succesfull compilation but an error message too :

"Unable to load assembly : Unsupported parameter type 'boolean' "

Hi,

from what I have read I don't think you can use a boolean as a parameter.

To solve this I use an integer and set it to 1 or 0 (to represent true and false).

I would rather use a boolean as the user would be restricted as to what input they can enter, and the programming is neater. But as the user is me and I know not to enter a different value it works.

TraderM


@TraderM

TraderM
02 Mar 2013, 15:49 ( Updated at: 21 Dec 2023, 09:20 )

The entry above did not display the pasted in  images, so I will try again:

----------------------------------

Hi,

1. If I set the default value of a parameter to 0 0.00015 value is shown in the parameter list as expected:

      [Parameter("Better entry ", DefaultValue = 0.00015, MinValue = 0)] // Try to get a better entry than the signal
      public double BetterEntry { get; set; }   

Note: This value is greater than one pip (AUDUSD)

But:

2. If I set the default value for the parameter to be less than 0.0001 like this:

      [Parameter("Better entry ", DefaultValue = 0.00005, MinValue = 0)] // Try to get a better entry than the signal
      public double BetterEntry { get; set; }   

the display shows the following:

Note: Trying to enter a value less than one pip (AUDUSD) fails.

3. Also if I use the parameter set in 1. above and enter 0.00005 by hand the 5E-05 is displayed as in 2:

This is awkward as I cannot enter a value in the interface to be less that one pip.

Why does this happen? Is this wanted behaviour?

Thanks,

TraderM


@TraderM

TraderM
10 Feb 2013, 21:33

Hi,

good news - the plaform ran all last week (with two robots running on Win 8) with no problems. The only known difference is that I deinstalled the Norton Online Backup.

I will update this post if the error appears again.

TraderM

 


@TraderM

TraderM
02 Feb 2013, 13:02

Hi,

the platform ran as expected until the end of the week when the same error occured again.

However I have noticed that two programs are active near the time of the crash (which seems to occur at a regular time):

- antivirus (update)

- Norton Online Backup (reminder to update)

I have now deinstalled Norton Online Backup.

It is awkward to sync the out of memory error with the event writer logs as I cannot get an exact time when the problem occurs (as I cannot watch the computer constatntly). But I think I will get there in the end.

The next step will be to run the platfrom again without Norton, then if the error still occurs try another antivirus. And keep watching the event writer.

I will keep you posted with any developments.

TraderM


@TraderM

TraderM
19 Jan 2013, 15:23

Hi,

I will run the robot another week real time just to check that the error does not result from network problems (to save you going through the code).

I would still be interested if there are additional error codes related to an Order Execution Error which I can intercept.

I know about these:BadVolume, TechnicalError, NoMoney, Disconnected, MarketClosed

Are there any other error messages that might relate to an Order Execution Error?

Thanks,

TraderM


@TraderM

TraderM
30 Dec 2012, 22:04

Hi, does this only work in real time? Backtesting, I get nothing written to the screen.

The example in the API reference under DrawText (example 1) starts:

if(IsRealTime)
....

which implies that this is indeed a solution for real time. If so, is it possible to write to the chart when backtesting?

What I really want to do is to highlight in the charts where I create/delete pending orders, enter and exit  trades and so on, when back testing. Currently I have to find the places in the charts going back and forth using the account history or the log with my Print functions. This takes ages...

Any ideas how to do this?

/M

 

 


@TraderM