Replies

AndreaPereira
04 Feb 2024, 15:49 ( Updated at: 04 Feb 2024, 16:27 )

Daily profit

Thanks a lot Lanikeha, I will try the code soon and let you know. Good day.

Update: It works.

Lanikeha said: 

firemyst said: 

//Get the historical trade stuff.
HistoricalTrade ht = History.FindLast(yourposition.Label, yourposition.SymbolName, yourposition.TradeType)

 


@AndreaPereira

AndreaPereira
24 Jan 2024, 14:17

RE: Daily profit

Hey, thanks for the help, I'll try to implement what you wrote, then I'll tell you if it works.

firemyst said: 

//Get the historical trade stuff.
HistoricalTrade ht = History.FindLast(yourposition.Label, yourposition.SymbolName, yourposition.TradeType);

 

 


@AndreaPereira

AndreaPereira
19 Jan 2024, 15:50

How to make string variable writable?

I tried…it doesn't compile...it says regex. it does not exist as a method.

meeting.chegini said: 

hi, Check this code, I hope it solves your problem

 

 


@AndreaPereira

AndreaPereira
19 Jan 2024, 14:34

How to make string variable writable?

Hi Chegini,

Thanks for the help, now I'll see if it solves the problem.. :)

 

meeting.chegini said: 

hi, Check this code, I hope it solves your problem

 


@AndreaPereira

AndreaPereira
19 Jan 2024, 11:46

How to make string variable writable?

eheh I mostly read the API reference. Give me time, I'm becoming much more skilled these days thanks to you too. So nothing can be done as I understand it??

 

Hi there, 

It seems you haven't read the documentation carefully :) You don't need a for loop and the method does not work on the current string, it returns a new one with the character replaced.

Best regards,

Panagiotis

 


@AndreaPereira

AndreaPereira
18 Jan 2024, 11:16 ( Updated at: 18 Jan 2024, 14:11 )

How to make string variable writable?

Thanks, I'll go and test...

 

This function should solve the comma problem on the textbox. When I enter floating point text with the period, the function should replace the period with the comma. But it doesn't work, what am I doing wrong? or is there a better solution to do this? Thanks you Panagiotis.

private void TextBox_TextChanged(TextChangedEventArgs obj){
            
            char oldChar = '.';
            char newChar = ',';
            string str = obj.TextBox.Text;

            for (int i = 0; i < str.Length; i++){
                if (str[i] == oldChar){
                    str.Replace(oldChar,newChar);         
                }
            }        
            Quantity = Convert.ToDouble(str);
        }

 

PanagiotisCharalampous said: 

Hi there,

Use String.Replace() instead.

Best regards,

Panagiotis

 


@AndreaPereira

AndreaPereira
16 Jan 2024, 13:48

String to double conversion

Having found the problem, when I went to type the units I inserted the decimal part with the dot and therefore it gave me the integer. Instead I have to insert the comma.


@AndreaPereira

AndreaPereira
16 Jan 2024, 13:17

RE: RE: String to double conversion

I'll look at the code better today and then I'll let you know... thanks my friend.

So I do not see any problem

 


@AndreaPereira

AndreaPereira
15 Jan 2024, 20:29 ( Updated at: 16 Jan 2024, 14:35 )

String to double conversion

I would like to replace the dot with a comma but it tells me that I cannot worldify the str string, what can I do?

private void TextBox_TextChanged(TextChangedEventArgs obj){
            
            char oldChar = '.';
            char newChar = ',';
            string a;
            string str = obj.TextBox.Text;
           
            for (int i = 0; i < str.Length; i++){
                if (str[i] == oldChar) {
                    str[i] = newChar;    <------- PROBLEM
                    
                }
            }            
            Quantity = Convert.ToDouble(str);
        }

@AndreaPereira

AndreaPereira
15 Jan 2024, 12:35

String to double conversion

Hi Panagiotis,

I trade gold in lots. For example 0.22 units. Thanks for the help.

 

 

Hi Andrea,

It seems you are converting your Quantity from quantity to volume in units. Hence the input is translated to lots, not to units. What symbol are you trading and what is the lot size?

Best regards,

Panagiotis

 


@AndreaPereira

AndreaPereira
13 Jan 2024, 11:02 ( Updated at: 15 Jan 2024, 07:11 )

RE: String to double conversion

Good morning, thanks, I will try to do as you say. 

14-01---ok I managed it but it gives me a problem. I put a textBox that takes a string and saves it in the Quantity variable. The latter is linked to the Button_Click_Buy function. In the execution phase I enter a value in the textbox, for example 0.10, I click the button and it opens the position without the decimal part so 10.00.
Another example: I enter 0.01 and set the variable to 1.00. What did I do wrong? Thank's my friend.

 [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.20, MinValue = 0.01, Step = 0.01)]
 public double Quantity { get; set; }
 --
 --
 --
 private void TextBox_TextChanged(TextChangedEventArgs obj)
     {
         Quantity = Convert.ToDouble(obj.TextBox.Text);
     }

 

public void Button_Click_Buy(ButtonClickEventArgs obj)
    {
        var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
        ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, "zero");
    }

 

PanagiotisCharalampous said: 

Hi Andrea,

You can use Convert.ToDouble() method.

Best regards,

Panagiotis

 


@AndreaPereira

AndreaPereira
12 Jan 2024, 17:31 ( Updated at: 12 Jan 2024, 17:39 )

RE: Button event

I solved it with cbot and not with the indicator. However, I'm curious to see your solution. If you want I'll attach the code and tell me what you think.

 


@AndreaPereira

AndreaPereira
12 Jan 2024, 13:45 ( Updated at: 12 Jan 2024, 14:12 )

RE: Button event

here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC,AccessRights = AccessRights.None)]
    public class NewIndicator2 : Indicator
    {

        protected override void Initialize()
        {
             var stackPanel = new StackPanel
           {
               HorizontalAlignment = HorizontalAlignment.Right,
               VerticalAlignment = VerticalAlignment.Bottom,
               BackgroundColor = Color.Gold,
               Opacity = 0.7,           
           };    
           
           for (int i = 0; i < 2; i++)
           {
               var button = new Button();     
               if (i == 0)
               {
                   button.Text = "Buy";
                   button.Button_Click_Buy();
                   
               }else{
                   
                   button.Text = "Sell";
                   button.Button_Click_Sell();

              }
               
               button.Margin = 10;
               stackPanel.AddChild(button);
           }
           
           Chart.AddControl(stackPanel);
        }
        private void Button_Click_Buy(ButtonClickEventArgs  ????)
        {
             ?????????
        }
         private void Button_Click_Sell(ButtonClickEventArgs  ????)
        {
             ?????????
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = 
        }
    }
}

@AndreaPereira

AndreaPereira
12 Jan 2024, 12:27

Button event

Hi Panagiotis,

I'm creating an indicator that has two chart buttons, one opens a long position and the other short. Graphically I managed to implement them as you can see from the photo, but now I should implement the action or behavior. I helped myself with the examples and the guide provided by the site but I haven't succeeded yet. Thanks for the support.

PanagiotisCharalampous said: 

Hi Andrea,

You would need to provide a better explanation regarding how exactly you want to proceed. What exact information are you looking for?

Best regards,

Panagiotis

 


@AndreaPereira

AndreaPereira
10 Jan 2024, 12:33 ( Updated at: 11 Jan 2024, 06:21 )

RE: Information on open operations

Thanks for your patience but I'm new to programming. :)

PanagiotisCharalampous said: 

You can use Math.Round to round the result

 


@AndreaPereira

AndreaPereira
09 Jan 2024, 14:11 ( Updated at: 10 Jan 2024, 06:56 )

RE: Information on open operations

It worked, there's one last problem. I noticed that sometimes it gives me the decimal value that is longer than two digits, how can I overcome this problem?

 

 

PanagiotisCharalampous said: 

Hi there,

You can use the Positions property to achieve this. Here is an example.

var netProfit = Positions.Sum(p => p.NetProfit);

Best regards,

Panagiotis

 


@AndreaPereira

AndreaPereira
09 Jan 2024, 11:45 ( Updated at: 10 Jan 2024, 06:56 )

RE: Information on open operations

Thanks, now I'll try to integrate this statement..


@AndreaPereira