Hi I forgot to reply to this but I tried using this but it's giving the same results. I also have been setting it in pips rather than relative prices before already
Well what you have provided above is evidently wrong. If you fix the code, try it again and you still have issues, feel free to repost it and we can have a look
Hi there! I double checked my code and parameters and I don't think I am placing it in their relative prices but pips instead, I'll leave the code below along with the parameters I placed
using System;using System.Linq;using cAlgo.API;using cAlgo.API.Indicators;using cAlgo.API.Internals;using cAlgo.Indicators;using System.Collections.Generic;namespace cAlgo.indicators{ [Robot(TimeZone = TimeZones.CentralPacificStandardTime, AccessRights = AccessRights.None)] public class Chasm : Robot { string version_number = "1.0"; // Declarations private int currenthour; private int currentminute; private string stringdate; private bool is_position_open; private string scenario; private double today_open; private double today_high; private double today_low; private double bid_price; private double ask_price; private double yesterday_close; private double yesterday_high; private double yesterday_low; private int kindex; [Parameter("N. Contracts", DefaultValue = 1, MinValue = 0)] public int ncontracts { get; set; } // Additional parameters [Parameter("Order Time (HH:mm)", DefaultValue = "01:28")] public string orderTime { get; set; } [Parameter("Order Expiry (Minutes)", DefaultValue = 2, MinValue = 1)] public double orderTimer { get; set; } [Parameter("Stop Loss Distance (Pips)", DefaultValue = 15, MinValue = 0, Group = "Buy Order Settings")] public double BuyStopLossAfterPips { get; set; } [Parameter("Take Profit (Pips)", DefaultValue = 40, MinValue = 0, Group = "Buy Order Settings")] public double BuyTakeProfitAfterPips { get; set; } [Parameter("Stop Loss Distance (Pips)", DefaultValue = 15, MinValue = 0, Group = "Sell Order Settings")] public double SellStopLossAfterPips { get; set; } [Parameter("Take Profit (Pips)", DefaultValue = 40, MinValue = 0, Group = "Sell Order Settings")] public double SellTakeProfitAfterPips { get; set; } protected override void OnStart() { is_position_open = false; kindex = 0; Positions.Closed += PositionsOnClosed; Print("Chasm {0} Started", version_number); Print("Server time is {0}", Server.Time.AddHours(0)); Timer.Start(60); } protected override void OnBar() { kindex = Bars.ClosePrices.Count - 1; today_open = Bars.OpenPrices[kindex]; yesterday_close = Bars.ClosePrices[kindex - 1]; yesterday_high = Bars.HighPrices[kindex - 1]; yesterday_low = Bars.LowPrices[kindex - 1]; if (today_open > yesterday_close) scenario = "GAPUP"; else if (today_open < yesterday_close) scenario = "GAPDOWN"; else scenario = null; } protected override void OnTimer() { today_high = Bars.HighPrices[kindex]; today_low = Bars.LowPrices[kindex]; // Time Vars stringdate = Server.Time.ToString("HH:mm"); currenthour = int.Parse(stringdate.Substring(0, 2)); currenthour = Convert.ToInt32(stringdate.Substring(0, 2)); currentminute = int.Parse(stringdate.Substring(3, 2)); currentminute = Convert.ToInt32(stringdate.Substring(3, 2)); bid_price = Symbol.Bid; ask_price = Symbol.Ask; if (scenario != null) { if (stringdate.Equals(orderTime)) ExecuteOrder(); } } protected override void OnStop() { Print("Chasm Stopped"); } private void PositionsOnClosed(PositionClosedEventArgs args) { var pos = args.Position; Print("Position closed with €{0} profit", pos.GrossProfit); is_position_open = false; } private void ExecuteOrder() { if (is_position_open) return; double lastLowPrice = Bars.LowPrices.Last(1); double lastHighPrice = Bars.HighPrices.Last(1); DateTime expiry = Server.Time.AddMinutes(orderTimer); var entryPrice = lastLowPrice; TradeResult sellResult = PlaceStopOrder(TradeType.Sell, SymbolName, ncontracts, entryPrice, "", SellStopLossAfterPips, SellTakeProfitAfterPips, expiry); if (sellResult.IsSuccessful) Print("Sell Stop Order placed at: " + entryPrice); else Print("Failed to place Sell Stop Order: " + sellResult.Error); entryPrice = lastHighPrice; TradeResult buyResult = PlaceStopOrder(TradeType.Buy, SymbolName, ncontracts, entryPrice, "", BuyStopLossAfterPips, BuyTakeProfitAfterPips, expiry); if (buyResult.IsSuccessful) Print("Buy Stop Order placed at: " + entryPrice); else Print("Failed to place Buy Stop Order: " + buyResult.Error); is_position_open = true; } }}
It uses the last x prices defined by the MA period including the current one.
Best regards,
Panagiotis
thank you. I use the closing price of the candlestick for SMA calculation, but in real time, the candlestick is not completed yet. What should I use instead of the closing price in such a case?
Hi I forgot to reply to this but I tried using this but it's giving the same results. I also have been setting it in pips rather than relative prices before already
Well what you have provided above is evidently wrong. If you fix the code, try it again and you still have issues, feel free to repost it and we can have a look
Your comment does not make much sense to me. Can you provide examples of what do you thing is wrong?
Best regards,
Panagiotis
Hi, I have the same problem. The take profit is 2 times less than it should be or so. For example, I place an order with a market with a fixed take of 1 to 4, after the price reaches the take, my profit is not 1 to 4, but 1 to 2 or 1 to 3. It's smaller than it should be. Help please
Hi there,
You need to refresh your math a bit :) It would be 1:4 if you started from 0%. But you start from 100% so it is 1:3.
cTrader does not add brokers to the platform. It's the brokers that add platforms to their offerings. So it is better to talk to the broker regarding this.
We did not change anything, we just propagate what we receive from the liquidity providers. Each liquidity provider has its own logic in streaming price feeds.
You can develop a simple cBot for this (or have a professional develop it for you). This is not something that will find it's way as a built in feature of the platform.
Please provide more information like your cBot's code, your broker and optimization dates, settings and parameters so that we can reproduce the problem.
You need to provide more information on your request if you expect to receive any help. Which trade options panel are you referring to? What do you expect to happen and what happens instead?
Your code logic is wrong. Your code does not do the below
I would like the buy/sell position to start as soon as the oposite SAR is touched
Your code just places trades when the price is above or below the current psar value, which is always true. You should check for crosses instead e.g. the close price being above while the open price is below.
PanagiotisCharalampous
26 Mar 2024, 06:44
Hi there,
What exactly is not working? What do you expect to happen and what happens instead?
Best regards,
Panagiotis
@PanagiotisCharalampous