Topics
Replies
firemyst
09 Dec 2022, 04:04
I found the best way to play sounds is to use the built in system sounds, and then assign your wave file to the system sound through the Control Panel.
Sample code:
if (AlertSoundToPlay == AlertSoundsOptions.Exclamation)
System.Media.SystemSounds.Exclamation.Play();
else if (AlertSoundToPlay == AlertSoundsOptions.Asterisk)
System.Media.SystemSounds.Asterisk.Play();
else if (AlertSoundToPlay == AlertSoundsOptions.Beep)
System.Media.SystemSounds.Beep.Play();
else if (AlertSoundToPlay == AlertSoundsOptions.Hand)
System.Media.SystemSounds.Hand.Play();
else if (AlertSoundToPlay == AlertSoundsOptions.Question)
System.Media.SystemSounds.Question.Play();
else
System.Media.SystemSounds.Exclamation.Play();
@firemyst
firemyst
24 Nov 2022, 06:07
RE:
alexnikon said:
Dear cTrader, how can I switch to use the Visual Studio 2022?
Have you installed VS 2022? If so, you might need to change your Windows settings for default programs. Eg, right click on your Visual Studio Project or solution file and set VS 2022 as the default application instead of VS 2019, 2017, or whatever you have
@firemyst
firemyst
24 Nov 2022, 06:03
RE:
rgasch said:
Hi,
could someone who knows please clarify what the Supertrend UpTrend() and DownTrend() methods actually return and why the sample code compares them to Bars.LowPrices/HighPrices?
Thank you
This is the sample code I'm referencing:
namespace cAlgo.Robots
{
// This sample cBot shows how to use the Supertrend indicator
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SupertrendSample : Robot
{
private double _volumeInUnits;private Supertrend _supertrend;
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }[Parameter("Stop Loss (Pips)", DefaultValue = 10)]
public double StopLossInPips { get; set; }[Parameter("Take Profit (Pips)", DefaultValue = 10)]
public double TakeProfitInPips { get; set; }[Parameter("Label", DefaultValue = "Sample")]
public string Label { get; set; }public Position[] BotPositions
{
get
{
return Positions.FindAll(Label);
}
}protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);_supertrend = Indicators.Supertrend(10, 3);
}protected override void OnBar()
{
if (_supertrend.UpTrend.Last(1) < Bars.LowPrices.Last(1) && _supertrend.DownTrend.Last(2) > Bars.HighPrices.Last(2))
{
ClosePositions(TradeType.Sell);ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
else if (_supertrend.DownTrend.Last(1) > Bars.HighPrices.Last(1) && _supertrend.UpTrend.Last(2) < Bars.LowPrices.Last(2))
{
ClosePositions(TradeType.Buy);ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
}private void ClosePositions(TradeType tradeType)
{
foreach (var position in BotPositions)
{
if (position.TradeType != tradeType) continue;ClosePosition(position);
}
}
}
}
The UpTrend() and DownTrend() methods return the values when the Supertrend is in an uptrend or downtrend.
There will be a value for one or the other, but not both, because the SuperTrend can't be in both an uptrend and downtrend at the same time.
@firemyst
firemyst
24 Nov 2022, 05:59
RE:
vvictord said:
Still looking for someone with these skills hehe
All you have to do is similar to the following:
//Create your parameter
[Parameter("Max Num of Open Positions", DefaultValue = 3)]
public int MaxNumberOfAllowedOpenTrades { get; set; }
//And in your code, do the check:
if (Positions.Count <= MaxNumberOfAllowedOpenTrades)
{
//do your stuff
}
else
{
Print ("Too many positions already opened.");
}
@firemyst
firemyst
04 Nov 2022, 11:02
RE: RE:
MongolTrader said:
firemyst said:
Why do you need to check it in a while loop? What's your logic or what are you trying to accomplish?
I need to know continuously every tick or bar what was last overbought or oversold point.
What I would consider doing then is:
1) in your OnStart do the while loop and find the last overbought/sold
2) create a class variable and store the index of the last overbought bar index in it
3) for every onbar event, check the stoch. If it's overbough/sold, update the global variation with the new bar number.
When you want bots running fast to respond to the market, so no need to execute a loop every single time a new bar or tick occurs.
@firemyst
firemyst
03 Nov 2022, 01:45
Hi there,
Looks like you've made good progress!
This is correct - well done!
_marketSeries2 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);
_marketSeries1 = MarketData.GetBars(TimeFrame.Minute15, Symbol.Name);
macd_1 = Indicators.MacdCrossOver(_marketSeries1.ClosePrices, LongPeriod1, ShortPeriod1, SignalPeriod1);
macd_2 = Indicators.MacdCrossOver(_marketSeries2.ClosePrices, LongPeriod2, ShortPeriod2, SignalPeriod2);
If you're unsure that you're getting the values you are expecting, then put Print statements in your code to print out the values and you can compare against having MACD indicators on your charts.
Example Print statement:
Print("MACD1 Value {0}, MACD1 Prev {1}", MACDLine1, PrevMACDLine1);
@firemyst
firemyst
02 Nov 2022, 16:22
RE:
valerijabramov24 said:
I have created my own cBot code and applied multiple instruments but it does not all work all the instruments parallelly. Only it is placing the order in active chart.
It does not work non interactive charts. is that expected ?
I am running multiple bots with multiple bot instances and they all place trades when they should -- not just on an active chart if I have an active chart (because when you run bots you don't necessarily have to have a chart open)
@firemyst
firemyst
01 Nov 2022, 00:59
Your code isn't going to work, because you're not creating the marketseries variables correctly:
_marketSeries2 = MarketData.GetBars(macd2, Symbol.Name);
_marketSeries1 = MarketData.GetBars(macd1, Symbol.Name);
The method is "GetBars", so why are you passing in the macd indicators? The first parameter of the GetBars method is the TIMEFRAME, not an indicator.
You are also not creating/initializing the MACD indicator as I showed you in my example -- the first parameter should be the data series, not the long period.
Please go back and reread my example making sure you understand it.
Spotware also has an example on their website which should help:
https://help.ctrader.com/ctrader-automate/indicator-code-samples/#multiple-timeframes
@firemyst
firemyst
31 Oct 2022, 13:51
( Updated at: 21 Dec 2023, 09:23 )
RE:
Alwin123 said:
How to use 2 macd different timeframe
I can't get past this.
anyone who can improve the script? Both macd must indicate the same sentiment before opening a trade. Preferably above or below the zero line
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class PullbackStrategy : Robot
{[Parameter("Sentiment: Buy", Group = "Sentiment", DefaultValue = true)]
public bool Buy { get; set; }[Parameter("Sentiment: Sell", Group = "Sentiment", DefaultValue = true)]
public bool Sell { get; set; }[Parameter("Another Time Frame MACD ", Group = "Strategy", DefaultValue = "Hour")]
public TimeFrame Multitimeframe { get; set; }[Parameter("Source", Group = "RSI")]
public DataSeries SourceRSI { get; set; }[Parameter("Periods", Group = "RSI", DefaultValue = 19)]
public int PeriodsRSI { get; set; }[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }[Parameter("Stop Loss ", Group = "Risk Managment", DefaultValue = 100)]
public int StopLoss { get; set; }[Parameter("Take Profit", Group = "Risk Managment", DefaultValue = 100)]
public int TakeProfit { get; set; }
public ExponentialMovingAverage i_MA_slow;
public ExponentialMovingAverage i_MA_standart;
public ExponentialMovingAverage i_MA_fast;
private RelativeStrengthIndex rsi;
private MacdCrossOver macd;
private MacdCrossOver MultitimeframeMACD;
private double volumeInUnits;
private Position position;
protected override void OnStart(){
i_MA_slow = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 50);
i_MA_standart = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 20);
i_MA_fast = Indicators.ExponentialMovingAverage(Bars.ClosePrices, 8);
rsi = Indicators.RelativeStrengthIndex(SourceRSI, PeriodsRSI);
macd = Indicators.MacdCrossOver(26, 12, 9);
MultitimeframeMACD = Indicators.MacdCrossOver(26, 12, 9);
volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
Positions.Opened += OnPositionsOpened;
Positions.Closed += OnPositionsClosed;
}void OnPositionsClosed(PositionClosedEventArgs obj)
{
position = null;
}void OnPositionsOpened(PositionOpenedEventArgs obj)
{
position = obj.Position;
}
[Obsolete]
protected override void OnBar()
{
var MACDLine = macd.MACD.Last(1);
var PrevMACDLine = macd.MACD.Last(2);
var Signal = macd.Signal.Last(1);
var PrevSignal= macd.Signal.Last(2);// both macd must be above the zero line for an entry buy or sell
var MultitimeframeMACD = MarketData.GetSeries(Multitimeframe);
var Multitimeframe = MultitimeframeMACD.MACD.Last(1);
var PrevMACDLineMultiTF = MultitimeframeMACD.MACD.Last(2);
var SignalMultiTF = MultitimeframeMACD.Signal.Last(1);
var PrevSignalMultiTF = MultitimeframeMACD.Signal.Last(2);if (position != null)
return;
{
if (rsi.Result.LastValue > 25 && rsi.Result.LastValue < 70)
{
int index = MarketSeries.Close.Count;if (MACDLine > Signal & PrevMACDLine <PrevSignal & default==Sell
& Multitimeframe > SignalMultiTF & PrevMACDLineMultiTF < PrevSignalMultiTF & default == Sell
& i_MA_fast.Result[index - 2] > MarketSeries.Close[index - 2]
& i_MA_fast.Result[index - 1] < MarketSeries.Close[index - 1]
& i_MA_fast.Result.LastValue < i_MA_standart.Result.LastValue
& i_MA_fast.Result.LastValue < i_MA_slow.Result.LastValue
& i_MA_standart.Result.LastValue < i_MA_slow.Result.LastValue)
{
ExecuteMarketOrder( TradeType.Buy, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
}
else if (MACDLine < Signal & PrevMACDLine >PrevSignal & default== Buy
& Multitimeframe > SignalMultiTF & PrevMACDLineMultiTF < PrevSignalMultiTF & default == Buy
& i_MA_fast.Result[index - 2] < MarketSeries.Close[index - 2]
& i_MA_fast.Result[index - 1] > MarketSeries.Close[index - 1]
& i_MA_fast.Result.LastValue > i_MA_standart.Result.LastValue
& i_MA_fast.Result.LastValue > i_MA_slow.Result.LastValue
& i_MA_standart.Result.LastValue > i_MA_slow.Result.LastValue){
ExecuteMarketOrder( TradeType.Sell, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
}
}
}
}
protected override void OnStop()
{
}
}
}
HI @Alwin123:
Your code isn't going to work, because you have to pass in a different time frame series when you create the MACD indicator.
It'll be something like this:
private Bars _marketSeriesH1;
MacdCrossOver macd;
//In the OnStart method, do something like this. This will get the data for the H1 timeframe:
_marketSeriesH1 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);
//This gets the MACD with the above time frame set (eg, H1 in this case):
macd = Indicators.MacdCrossOver(_marketSeriesH1.ClosePrices, LongPeriod, ShortPeriod, SignalPeriod);
@firemyst
firemyst
31 Oct 2022, 13:50
RE:
PanagiotisChar said:
Hi Waxy,
Did you try
[Parameter("Color", DefaultValue = "Red")] public MyColors Color { get; set; }
Need help? Join us on Telegram
Need premium support? Trade with us
HI @PanagiotisChar:
I believe it's broken in the latest cTrader release, because the code below doesn't work for me any more either. It always comes up with a default value of "Yesterday" instead of "Three_Weeks":
public enum LoadFromData
{
Yesterday,
Today,
Two_Days,
Three_Days,
One_Week,
Two_Weeks,
Three_Weeks,
Monthly,
Custom
}
[Parameter("Amount of Historic Data to Load:", DefaultValue = LoadFromData.Three_Weeks)]
public LoadFromData LoadFromInput { get; set; }
@firemyst
firemyst
31 Oct 2022, 13:45
HI @Alwin123:
Your code isn't going to work, because you have to pass in a different time frame series when you create the MACD indicator.
It'll be something like this:
private Bars _marketSeriesH1;
MacdCrossOver macd;
//In the OnStart method, do something like this. This will get the data for the H1 timeframe:
_marketSeriesH1 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);
//This gets the MACD with the above time frame set (eg, H1 in this case):
macd = Indicators.MacdCrossOver(_marketSeriesH1.ClosePrices, LongPeriod, ShortPeriod, SignalPeriod);
@firemyst
firemyst
27 Oct 2022, 12:11
( Updated at: 21 Dec 2023, 09:23 )
RE:
mindfulness said:
Hello,
even with using the memory manager, the used memory is increasing overtime and i have to restart the bot after maybe two days. Is there another way to handle it?
For example on one VPS there are running two ctrade instances. One with 37 pairs/bots and one with 15. The VPS has 4 cores and 8 GB RAM. Here the usage after one day.
How much writing to the log does the bot do? Eg, PRINT statements? You can't clear the log programmatically, and constantly writing to it will suck up memory.
@firemyst
firemyst
22 Dec 2022, 14:06
> Does this mean that the data will be sent to the developer of the cBot?
Not necessarily. It depends on what the programmer of the bot programmed. If the programmer wrote code to do so, then yes; if the programmer didn't, then no.
> Are there any data going to the third parties or the maker of the cBot?
Again, there could be. It all depends on what the programmer did.
@firemyst